As for your first question: "if item is in my_list:" is perfectly fine and should work if item equals one of the elements inside my_list. The item must exactly match an item in the list. For instance, "abc" and "ABC" do not match. Floating point values in particular may suffer from inaccuracy. For instance, 1 - 1/3 != 2/3.

As for your second question: There's actually several possible ways if "finding" things in lists.

Checking if something is inside

This is the use case you describe: Checking whether something is inside a list or not. As you know, you can use the in operator for that:

3 in [1, 2, 3] # => True

Filtering a collection

That is, finding all elements in a sequence that meet a certain condition. You can use list comprehension or generator expressions for that:

matches = [x for x in lst if fulfills_some_condition(x)]
matches = (x for x in lst if x > 6)

The latter will return a generator which you can imagine as a sort of lazy list that will only be built as soon as you iterate through it. By the way, the first one is exactly equivalent to

matches = filter(fulfills_some_condition, lst)

in Python 2. Here you can see higher-order functions at work. In Python 3, filter doesn't return a list, but a generator-like object.

Finding the first occurrence

If you only want the first thing that matches a condition (but you don't know what it is yet), it's fine to use a for loop (possibly using the else clause as well, which is not really well-known). You can also use

next(x for x in lst if ...)

which will return the first match or raise a StopIteration if none is found. Alternatively, you can use

next((x for x in lst if ...), [default value])

Finding the location of an item

For lists, there's also the index method that can sometimes be useful if you want to know where a certain element is in the list:

[1,2,3].index(2) # => 1
[1,2,3].index(4) # => ValueError

However, note that if you have duplicates, .index always returns the lowest index:......

[1,2,3,2].index(2) # => 1

If there are duplicates and you want all the indexes then you can use enumerate() instead:

[i for i,x in enumerate([1,2,3,2]) if x==2] # => [1, 3]
Answer from Niklas B. on Stack Overflow
Top answer
1 of 14
1828

As for your first question: "if item is in my_list:" is perfectly fine and should work if item equals one of the elements inside my_list. The item must exactly match an item in the list. For instance, "abc" and "ABC" do not match. Floating point values in particular may suffer from inaccuracy. For instance, 1 - 1/3 != 2/3.

As for your second question: There's actually several possible ways if "finding" things in lists.

Checking if something is inside

This is the use case you describe: Checking whether something is inside a list or not. As you know, you can use the in operator for that:

3 in [1, 2, 3] # => True

Filtering a collection

That is, finding all elements in a sequence that meet a certain condition. You can use list comprehension or generator expressions for that:

matches = [x for x in lst if fulfills_some_condition(x)]
matches = (x for x in lst if x > 6)

The latter will return a generator which you can imagine as a sort of lazy list that will only be built as soon as you iterate through it. By the way, the first one is exactly equivalent to

matches = filter(fulfills_some_condition, lst)

in Python 2. Here you can see higher-order functions at work. In Python 3, filter doesn't return a list, but a generator-like object.

Finding the first occurrence

If you only want the first thing that matches a condition (but you don't know what it is yet), it's fine to use a for loop (possibly using the else clause as well, which is not really well-known). You can also use

next(x for x in lst if ...)

which will return the first match or raise a StopIteration if none is found. Alternatively, you can use

next((x for x in lst if ...), [default value])

Finding the location of an item

For lists, there's also the index method that can sometimes be useful if you want to know where a certain element is in the list:

[1,2,3].index(2) # => 1
[1,2,3].index(4) # => ValueError

However, note that if you have duplicates, .index always returns the lowest index:......

[1,2,3,2].index(2) # => 1

If there are duplicates and you want all the indexes then you can use enumerate() instead:

[i for i,x in enumerate([1,2,3,2]) if x==2] # => [1, 3]
2 of 14
281

If you want to find one element or None use default in next, it won't raise StopIteration if the item was not found in the list:

first_or_default = next((x for x in lst if ...), None)
🌐
W3Schools
w3schools.com › Python › ref_list_index.asp
Python List index() Method
MongoDB Get Started MongoDB Create DB MongoDB Collection MongoDB Insert MongoDB Find MongoDB Query MongoDB Sort MongoDB Delete MongoDB Drop Collection MongoDB Update MongoDB Limit ... Python Overview Python Built-in Functions Python String Methods Python List Methods Python Dictionary Methods ...
Discussions

Why doesn't python lists have a .find() method?
It actually exists for all iterators, its just called next. next((i for i in users if i['id'] == 2), None) More on reddit.com
🌐 r/Python
55
42
May 6, 2022
Adding the method find() to list - Ideas - Discussions on Python.org
Before I talk about the real topic, I have to ask if the discussion of enhancements should start here, because I already created a issue in the issue tracker. It is Ok to just create it, or the discussion should start here? Now the real topic: . . . “”" PROBLEM: When trying to search the ... More on discuss.python.org
🌐 discuss.python.org
0
May 6, 2020
Finding a sublist anywhere within a list

Okay, first of all, <= doesn't detect sublists, it checks if the list is "lower or equal". For lists that means that beginning from the first item, every item is compared until two items are found that are different. Like [1, 2] < [1, 3] is True, since 2 < 3. This shouldn't be used to check for sublists though, because [1, 1] <= [1, 2, 3] is also True, but [1, 1] is not a sublist of [1, 2, 3]

Python doesn't ship a sublist function, so you have to write one by yourself, like this

def isSublist(a, b):
    if len(a) > len(b):
        return False
    for i in range(0, len(b) - len(a) + 1):
        if b[i:i+len(a)] == a:
            return True
    return False

this will check if a is a sublist of b, so isSublist([2, 3], [1, 2, 3, 4]) should return True. This works by walking through the second list (the list in which we're searching) and comparing the sublist b[i:i+len of the sublist we're searching] to the sublist we're searching (if you don't know that syntax, you should read on slice notations in the Python doc).

I hope I could help, if you have more questions feel free to ask :)

More on reddit.com
🌐 r/learnpython
11
5
March 19, 2014
beautifulsoup - How to get_text from item retrieved using find_all ('tag', 'class')
If there's just one: soup.body.find('p', class_="cite").text Or if there's more than one, using .find_all, you get a bs4.element.ResultSet which acts like a list whose elements are bs4.element.Tag, meaning you can call .text on them individually too. As in: for x in soup.body.find_all('p', class_="cite"): print(x.text) More on reddit.com
🌐 r/learnpython
5
6
July 28, 2013
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-list-index
Python List index() - Find Index of Item - GeeksforGeeks
index() method in Python is a helpful tool when you want to find the position of a specific item in a list. It works by searching through the list from the beginning and returning the index (position) of the first occurrence of the element you're ...
Published   April 27, 2025
🌐
Python documentation
docs.python.org › 3 › tutorial › datastructures.html
5. Data Structures — Python 3.14.6 documentation
This chapter describes some things you’ve learned about already in more detail, and adds some new things as well. More on Lists: The list data type has some more methods. Here are all of the method...
🌐
Reddit
reddit.com › r/python › why doesn't python lists have a .find() method?
r/Python on Reddit: Why doesn't python lists have a .find() method?
May 6, 2022 -

Doesn't it make sense for lists to have a find method?

class MyList(list):
    def find(self, func):
        for i in self:
            if func(i):
                return i
        return None
        # or raise ValueError?


users = [
    {
        'id': 1,
        'name': 'john',
    },
    {
        'id': 2,
        'name': 'anna',
    },
    {
        'id': 3,
        'name': 'bruce',
    }
]

my_list = MyList(users)
user_2 = my_list.find(lambda i: i['id'] == 2)
print(user_2)  # {'id': 2, 'name': 'anna'}
🌐
freeCodeCamp
freecodecamp.org › news › python-find-in-list-how-to-find-the-index-of-an-item-or-element-in-a-list
Python Find in List – How to Find the Index of an Item or Element in a List
February 24, 2022 - Use the index() method to find the index of an item 1.Use optional parameters with the index() method · Get the indices of all occurrences of an item in a list · Use a for-loop to get indices of all occurrences of an item in a list · Use ...
Find elsewhere
🌐
Medium
medium.com › swlh › python-the-fastest-way-to-find-an-item-in-a-list-19fd950664ec
Python: The Fastest Way to Find an Item in a List | by Sebastian Witowski | The Startup | Medium
September 25, 2020 - Python: The Fastest Way to Find an Item in a List If you want to find the first number that matches some criteria, what do you do? The easiest way is to write a loop that checks numbers one by one …
🌐
Sentry
sentry.io › sentry answers › python › find item in list in python
Find item in list in Python | Sentry
2 weeks ago - my_list = [4, 8] odd_number = next((n for n in my_list if n%2), None) print(odd_number) # will print None ... Tasty treats for web developers brought to you by Sentry. Get tips and tricks from Wes Bos and Scott Tolinski. SEE EPISODES ... David Y. — November 15, 2023 ... David Y. — March 15, 2023 · Get the value of a DataFrame cell in Python Pandas
🌐
IronPDF
ironpdf.com › ironpdf blog › pdf tools › python-find-in-lists
Python Finding Elements in Lists (Beginner-Friendly Guide)
April 24, 2026 - Find Duplicates Using List Comprehension. Find Element Exists Using the "filter()" Function. Find Element Exists Using External Libraries. Install Python: Make sure Python is installed on the local machine, or visit python.org to follow the steps to install Python.
🌐
Python.org
discuss.python.org › ideas
Adding the method find() to list - Ideas - Discussions on Python.org
May 6, 2020 - Now the real topic: . . . “”" PROBLEM: When trying to search the position of an element inside a list, we should use the in operator to first check if the element exists, and then use the index method to obtain the index. in (__contains__) ...
🌐
Programiz
programiz.com › python-programming › methods › list › index
Python List index()
The index() method returns the index of the specified element in the list.
🌐
Google
developers.google.com › google for education › python › python lists
Python Lists | Python Education | Google for Developers
If you know what sort of thing is in the list, use a variable name in the loop that captures that information such as "num", or "name", or "url". Since Python code does not have other syntax to remind you of types, your variable names are a key way for you to keep straight what is going on.
🌐
IronPDF
ironpdf.com › ironpdf for python › ironpdf for python blog › python pdf tools › python find in list
Python Find in List (How It Works For Developers)
April 22, 2026 - Let's incorporate a Python list operation with IronPDF extracted text. The following code demonstrates how to use the in operator to find specific text within the extracted content and then count the number of occurrences of each keyword.
🌐
Python Engineer
python-engineer.com › posts › find-index-of-item-in-list
How to find the index of an item in a List in Python - Python Engineer
Learn how the index of an item in Python Lists can be found. Patrick Loeber · · · · · August 03, 2021 · 2 min read · To find the index of an item in Python lists, you can simply use my_list.index():
🌐
Python Tutorial
pythontutorial.net › home › python basics › how to find the index of an element in a list
How to Find the index of an Element in a List in Python
March 26, 2025 - To find the index of an element in a list, you use the index() function. The following example defines a list of cities and uses the index() method to get the index of the element whose value is 'Mumbai': cities = ['New York', 'Beijing', 'Cairo', 'Mumbai', 'Mexico'] result = cities.index('Mumbai') ...
🌐
Python documentation
docs.python.org › 3 › library › re.html
re — Regular expression operations
May 25, 2026 - For example, (<)?(\w+@\w+(?:\.... finds only 'user@host.com' in the former). Changed in version 3.12: Group id can only contain ASCII digits. In bytes patterns, group name can only contain bytes in the ASCII range (b'\x00'-b'\x7f'). The special sequences consist of '\' and a character from the list ...
🌐
Lucidar
lucidar.me › en › python › search-item-in-list
Find elements in lists in Python | Lulu's blog
October 11, 2021 - This page explains how to search elements in lists in Python. | Lulu's blog | Philippe Lucidarme
🌐
Vultr Docs
docs.vultr.com › python › standard-library › list › index
Python List index() - Locate Element Index | Vultr Docs
November 7, 2024 - The index() method in Python is a straightforward way to find the position of an element in a list.