0 votes
1 view
in Data Science by (7.5k 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 (15.3k 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.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...