Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (18.4k points)

Say I have a

list=['apple','orange','durian','blackberry']

How do I find the position of 'durian' using while or for loops I know there's a code called list.index('durian') but I want to know the position of the specific item using for/while loops

1 Answer

0 votes
by (36.8k points)

You could use enumerate(...):

lst = ['apple', 'orange', 'durian', 'blackberry']

for idx, value in enumerate(lst):

    if value == "durian":

        print(idx)

Do check out Data Science with Python course which helps you understand from scratch.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...