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

Finding the index of an item in a List


Neha
 Neha
(@asha)
Member Admin
Joined: 11 months ago
Posts: 18
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?

This topic was modified 1 month ago by Neha

Govind and myTechMint liked
Quote
Topic Tags
myTechMint
(@mytechmint)
Eminent Member
Joined: 12 months ago
Posts: 20
 

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