Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to find the next index of a charachter in python list

I was dealing with python list and I want to find the next index of the recurring character in the list how can I accomplish that

country = ['Beekeeper', 'Fly', 'Hornet']


pickedCountry = random.choice(country)
let the pickedCountry = 'Beekeeper'
print(pickedCountry .index('e'),)

it print out only 1

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

pickedCountry = 'Beekeeper'
last_index = 0
while last_index < len(pickedCountry):
    current_index = pickedCountry.index('e', last_index)
    print(current_index)
    last_index = current_index + 1
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading