Back
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
You could use enumerate(...):
lst = ['apple', 'orange', 'durian', 'blackberry']for idx, value in enumerate(lst): if value == "durian": print(idx)
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