-2

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.

Max Limo
  • 13
  • 1

2 Answers2

-1

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

Snir Ego
  • 82
  • 6
-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
Alex Joslin
  • 131
  • 2
  • 5