So if I had a list of strings such as
a = ['apple', 'banana', 'orange']
how would I reverse each string in that list to make
a = ['elppa', 'ananab', 'egnaro']
So if I had a list of strings such as
a = ['apple', 'banana', 'orange']
how would I reverse each string in that list to make
a = ['elppa', 'ananab', 'egnaro']
How do you reverse single string?
word = 'apple'
print(word[::-1])
So
words = ['apple', 'banana', 'orange']
reversed_words = [word[::-1] for word in words]
This is how:
a = [y[::-1] for y in a]
print(a) # ['elppa', 'ananab', 'egnaro']
Do invest some time reading about slicing