[Solved] Python, finding position of a charater in a string


You can use list comprehension, with enumerate, like this

>>> [index for index, char in enumerate(s) if char == "l"]
[2, 3]

The enumerate function will give the current index as well the current item in the iterable. So, in each iteration, you will get the index and the corresponding character in the string. We are checking of the character is l and if it is l, we include the index in the resulting list.

1

solved Python, finding position of a charater in a string