I have this code for a program that replaces characters in a string for superscript characters, jumping 1 character every time.
Characters that are not in my dictionary should be skipped but also affect if the next character will be replaced (so, if the "not-in-dict-character" should be replaced, it is skipped and the next character is not replaced and vice-versa)
Blank spaces should be skipped without altering the next character.
letters = { # My dictionary for all the letters and superscript versions
'a' : 'ᵃ',
'b' : 'ᵇ',
'c' : 'ᶜ',
'd' : 'ᵈ',
'e' : 'ᵉ',
'f' : 'ᶠ',
'g' : 'ᵍ',
'h' : 'ʰ',
'i' : 'ᶦ',
'j' : 'ʲ',
'k' : 'ᵏ',
'l' : 'ˡ',
'm' : 'ᵐ',
'n' : 'ⁿ',
'o' : 'ᵒ',
'p' : 'ᵖ',
'q' : 'ᵠ',
'r' : 'ʳ',
's' : 'ˢ',
't' : 'ᵗ',
'u' : 'ᵘ',
'v' : 'ᵛ',
'w' : 'ʷ',
'x' : 'ˣ',
'y' : 'ʸ',
'z' : 'ᶻ',
'A' : 'ᴬ',
'B' : 'ᴮ',
'C' : 'ᶜ',
'D' : 'ᴰ',
'E' : 'ᴱ',
'F' : 'ᶠ',
'G' : 'ᴳ',
'H' : 'ᴴ',
'I' : 'ᴵ',
'J' : 'ᴶ',
'K' : 'ᴷ',
'L' : 'ᴸ',
'M' : 'ᴹ',
'N' : 'ᴺ',
'O' : 'ᴼ',
'P' : 'ᴾ',
'Q' : 'ᵠ',
'R' : 'ᴿ',
'S' : 'ˢ',
'T' : 'ᵀ',
'U' : 'ᵁ',
'V' : 'ⱽ',
'W' : 'ᵂ',
'X' : 'ˣ',
'Y' : 'ʸ',
'Z' : 'ᶻ'
}
x = 0
while True:
text = input('Insert text: ')
while True:
# This will ask if the user wants something like 'aᵃaᵃaᵃaᵃ' or 'ᵃaᵃaᵃaᵃa'
fos = input('Do you want the first or the second letter to be small?(f/s): ')
if fos != 'f':
if fos != 's':
print('Please insert \'f\' or \'s\' (for first and second letters).\n')
else:
break
else:
break
if fos == 'f':
x = 1
elif fos == 's':
x = 2
for e in text:
if x % 2 == 0: # If x value is even, it skips this character
x = x + 1 # Makes the x value odd, so the next character isn't skipped
continue
elif e == ' ': # Ignoring blank spaces
continue
elif e not in letters: # Ignoring characters that are not in my dict
x = x + 1
continue
elif e in letters:
text = text.replace(e, letters[e], 1) # The third parameter is
x = x + 1
print(text)
The problem is, if the character the replace function is trying to replace has a duplicate in the string, it doesn't care which one of the characters is 'e' and just replaces the first one in the string.
So, if the user inputs 'abaaba' and 'f', the result will be 'ᵃᵇᵃaba' when it should be 'ᵃbᵃaᵇa'. Is there any way to make the replace sensitive to which character in the string is e?