message = ["TS", "EE", "RE", "Z"]
So I'm trying to compare the characters within this list, and have conditions when some things arise such as if a value in the list for example "EE" is the same, it will return true and append a "Q" to separate the letters so the list looks like this
message = ["TS", "EQ", "ER" "EZ"]
So I tried it normally without looping it works but when I loop it says string index out of range.
a = ''
a = message[1]
if a[0] == a[1]:
print("True")
else:
print("False")
When looping
for i in range(len(message)):
a = ''
a = message[i]
if a[0] == a[1]:
print("True")
What should I do? Turn it into a string first and work on it?
1so you tried to access the the second element when there is no second element i.e.Out of index errora = ''lines are not accomplishing anything, since you replace the value ofaon the next line.Z) there is no position 1 since the string only consists of 1 character.