I want to check if the words in a list are palindromes, that is, if they read the same from right to left as from left to right.
This has occurred to me:
listT=['alba','aerea','alla','ana']
listF=['Roberto','Manuel','Jesus','Marea']
list1=listT + listF
for i in list1:
for j in list1[i]:
if id(j)==id(-j-1):
print('Es un palíndromo')
else:
print('No es un palíndromo')
But it gives error in the second for
:
TypeError: list indices must be integers or slices, not str
I had also thought of another way, using two indexes, but in Python you can't do it, for example:
lista1=['aerea','ana']
So that you can determine a letter from a list, for example the 'a' of "aerea":
lista1[0[0]]
And this way you could do:
listT=['alba','aerea','alla','ana']
listF=['Roberto','Manuel','Jesus','Marea']
list1=listT + listF
for i in list1:
for j in range(len(list1[i])):
if list1[i[j]]==list1[i[-j-1]]:
print('True')
else:
print('False')
This can't either. How would you determine a letter of a word from a list?