Python Forum

Full Version: How to get the index of a character from a string
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, i used this code it is getting the index value but i need it to get the index value as the expected output
s = 'Apples are totally awesome'
l = []
for idx, item in enumerate(s.lower()):
if 'a' in item:
l.append(idx)
if('l' in item) and ('a' in s[idx-1]):
l.append(idx)
print(l)

Actual output:
[0,7,14,15,20]

Expected output:
[0,7,14,15,16,20]
can you explain the desired output in plain english