Python Forum
How to get the index of a character from a string - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/Forum-Python-Coding)
+--- Forum: General Coding Help (https://python-forum.io/Forum-General-Coding-Help)
+--- Thread: How to get the index of a character from a string (/Thread-How-to-get-the-index-of-a-character-from-a-string)



How to get the index of a character from a string - chihaya - Dec-03-2019

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]


RE: How to get the index of a character from a string - buran - Dec-03-2019

can you explain the desired output in plain english