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

Finding the index of an item in a List


Neha
 Neha
(@asha)
Member Admin
Joined: 1 year ago
Posts: 27
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: 1 year ago
Posts: 31
 

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