Finding the index o...
 
Share:
Notifications
Clear all

Finding the index of an item in a List


Neha
 Neha
(@asha)
Member Admin
Joined: 4 years ago
Posts: 31
Topic starter  

Given a list ["foo", "bar", "baz"] and an item in the list "bar", how do I get its index of item "bar" in Python?


Govind and myTechMint liked
Quote
Topic Tags
myTechMint
(@mytechmint)
Member Moderator
Joined: 4 years ago
Posts: 52
 

You can achieve this by using index()

["foo", "bar", "baz"].index("bar")

Output:

1

Reference: Data Structures > More on Lists


Neha and Govind liked
ReplyQuote