How do I find an item in my list without using indexes.
So i have a list and I want to find the item in a list.
How do I find an item in my list without using indexes.
So i have a list and I want to find the item in a list.
If you have the list i would use this:
fruits = ['banana', 'apple', 'watermelon', 'peach']
index = fruits.index('apple')
print('The index of apple is:', index)
OUTPUT: 1
Are you simply checking to see if an item exists within the list?
If so user the in operator Example:
# Example
my_list = [4,5,7,2,4,5]
if 7 in my_list:
print("Item found")
Or if you are trying to return the index of the item found do this:
my_list.index(7)
# returns 2