How do I find an item in my list without using indexes

All we need is an easy explanation of the problem, so here it is.

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 to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

Are you simply checking to see if an item exists within the list?

If so user the in operator

# 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:

# returns 2

Method 2

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)


Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

Leave a Reply