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
🌐
IronPDF
ironpdf.com › ironpdf blog › pdf tools › python-find-in-lists
Python Find in Lists (How It Works For Developers)
April 30, 2024 - Find Element Exists Using the list "index()" Method. Find Element Exists Using List Comprehension. Find Duplicates Using List Comprehension. Find Element Exists Using the "filter()" Function.
Top answer
1 of 14
1823

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
279

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)
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-find-string-in-list
Python Find String in List: Complete Guide with Examples | DigitalOcean
February 25, 2025 - To search a string in a list in Python, you can use the in operator to check if the string is present in the list. For example: my_list = ["apple", "banana", "cherry"] if "banana" in my_list: print("Found!") Alternatively, you can use the index() method to find the index of the first occurrence ...
Top answer
1 of 3
7

I don't know why or maybe is buried in some PEP somewhere, but i do know 2 very basic "find" method for lists, and they are array.index() and the in operator. You can always make use of these 2 to find your items. (Also, re module, etc)

2 of 3
4

I think the rationale for not having separate 'find' and 'index' methods is they're not different enough. Both would return the same thing in the case the sought item exists in the list (this is true of the two string methods); they differ in case the sought item is not in the list/string; however you can trivially build either one of find/index from the other. If you're coming from other languages, it may seem bad manners to raise and catch exceptions for a non-error condition that you could easily test for, but in Python, it's often considered more pythonic to shoot first and ask questions later, er, to use exception handling instead of tests like this (example: Better to 'try' something and catch the exception or test if its possible first to avoid an exception?).

I don't think it's a good idea to build 'find' out of 'index' and 'in', like

if foo in my_list:
   foo_index = my_list.index(foo)
else:
    foo_index = -1 # or do whatever else you want

because both in and index will require an O(n) pass over the list.

Better to build 'find' out of 'index' and try/catch, like:

try:
    foo_index = my_list.index(foo)
catch ValueError:
    foo_index = -1 # or do whatever else you want

Now, as to why list was built this way (with only index), and string was built the other way (with separate index and find)... I can't say.

🌐
Python documentation
docs.python.org › 3 › tutorial › datastructures.html
5. Data Structures — Python 3.14.3 documentation
For example, 3+4j < 5+7j isn’t a valid comparison. The list methods make it very easy to use a list as a stack, where the last element added is the first element retrieved (“last-in, first-out”). To add an item to the top of the stack, use append(). To retrieve an item from the top of the stack, use pop() without an explicit index.
🌐
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__) ...
🌐
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'}
🌐
W3Schools
w3schools.com › python › ref_string_find.asp
Python String find() Method
Python Overview Python Built-in Functions Python String Methods Python List Methods Python Dictionary Methods Python Tuple Methods Python Set Methods Python File Methods Python Keywords Python Exceptions Python Glossary · Built-in Modules Random Module Requests Module Statistics Module Math Module cMath Module · Remove List Duplicates Reverse a String Add Two Numbers · Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... The find() method finds the first occurrence of the specified value.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python › list-methods-python
Python List methods - GeeksforGeeks
In the code below, we will extend the list by adding elements from another list. ... In the code below, we will find the index of a specific element in the list.
Published   July 23, 2025
🌐
W3Schools
w3schools.com › python › python_lists_methods.asp
Python - List Methods
Remove List Duplicates Reverse a String Add Two Numbers · Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... Python has a set of built-in methods that you can use on lists.
🌐
W3Schools
w3schools.com › python › python_ref_list.asp
Python List/Array Methods
Remove List Duplicates Reverse a String Add Two Numbers · Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... Python has a set of built-in methods that you can use on lists/arrays.
🌐
Programiz
programiz.com › python-programming › methods › list
Python List Methods | Programiz
Python has a lot of list methods that allow us to work with lists. In this reference page, you will find all the list methods to work with Python List. For example, if you want to add a single item to the end of the list, you can use the list.append() method.
🌐
Tutorialspoint
tutorialspoint.com › python › python_lists.htm
Python - Lists
For example − · list1 = ['physics', 'chemistry', 1997, 2000]; print (list1) del list1[2]; print ("After deleting value at index 2 : ") print (list1) When the above code is executed, it produces following result − · ['physics', 'chemistry', 1997, 2000] After deleting value at index 2 : ['physics', 'chemistry', 2000] Note − remove() method is discussed in subsequent section. In Python, List is a sequence.
🌐
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 - There are a few ways to achieve this, and in this article you will learn three of the different techniques used to find the index of a list element in Python. ... Use the index() method to find the index of an item 1.Use optional parameters ...
🌐
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
🌐
DataCamp
datacamp.com › tutorial › python-list-index
Python List index() Method Explained with Examples | DataCamp
March 28, 2025 - Learn how to use Python's index() function to find the position of elements in lists. ... Get your team access to the full DataCamp for business platform. In Python, a data structure helps you organize and store data efficiently. One common and versatile structure is a list, which can hold different types of data in a specific order. Python also provides many functions or methods for working with ...
🌐
Javatpoint
javatpoint.com › python-find-in-list
Python Find in List - Javatpoint
Python Find in List with tutorial, tkinter, button, overview, canvas, frame, environment set-up, first python program, etc.
🌐
DEV Community
dev.to › keploy › python-find-in-list-a-comprehensive-guide-6c6
Python Find in List: A Comprehensive Guide - DEV Community
January 8, 2025 - Whether you’re analyzing data, validating inputs, or filtering results, understanding how to locate elements in a list is essential for efficient coding. In this guide, we’ll explore various methods for finding elements in Python find in list, along with practical examples and tips.
🌐
Programiz
programiz.com › python-programming › methods › list › index
Python List index()
Before we wrap up, let’s put your knowledge of Python list index() to the test! Can you solve the following challenge? ... Write a function to find the index of a given element in a list. For example, with inputs [1, 2, 3, 4, 5] and 3, the output should be 2.
🌐
Sentry
sentry.io › sentry answers › python › find item in list in python
Find item in list in Python | Sentry
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.