From Dive Into Python:

>>> li
['a', 'b', 'new', 'mpilgrim', 'z', 'example', 'new', 'two', 'elements']
>>> li.index("example")
5
Answer from Matt Howell on Stack Overflow
🌐
Pythonspot
pythonspot.com › array-find
Python Find In Array — Tutorial with Examples | Pythonspot
January 1, 2026 - Arrays are usually referred to as lists. For convience, lets call them arrays in this article. Python has a method to search for an element in an array, known as index(). We can find an index using:
Discussions

numpy - python finding index of an array within a list - Stack Overflow
But that expression occurs where Python expects a scalar boolean. Test your code in small pieces. ... List index expects a scalar value when it applies an == test. ... Your last error message indicates that you are still mixing lists and arrays. I'll try to recreate the situation: Make a list of lists. Finding ... More on stackoverflow.com
🌐 stackoverflow.com
python - Find a value in a list - Stack Overflow
I use the following to check if item is in my_list: if item in my_list: print("Desired item is in list") Is "if item in my_list:" the most "pythonic" way of findi... More on stackoverflow.com
🌐 stackoverflow.com
python - Check if item is in an array / list - Stack Overflow
If I've got an array of strings, can I check to see if a string is in the array without doing a for loop? Specifically, I'm looking for a way to do it within an if statement, so something like thi... More on stackoverflow.com
🌐 stackoverflow.com
min() vs 'sort() and then list[0]'

As others have mentioned, min will be quicker. min just has to walk through the list once, whereas sort must do more compares, making it more complex.

However, one case you might want to use sort is when you need more than just the minimum. Eg. you want the 5 smallest items, not just the smallest. Here "sorted(mylist)[:5]" will do the job, but another option to keep in mind is the heapq module, as "heapq.nsmallest(5, mylist)" will often perform better than sort, at least for a small number of items.

More on reddit.com
🌐 r/Python
36
29
February 23, 2012
🌐
GeeksforGeeks
geeksforgeeks.org › python › find-element-in-array-python
Find element in Array - Python - GeeksforGeeks
July 23, 2025 - Finding an item in an array in Python can be done using several different methods depending on the situation.
🌐
IronPDF
ironpdf.com › ironpdf blog › pdf tools › python-find-in-lists
Python Finding Elements in Lists (Beginner-Friendly Guide)
April 24, 2026 - NumPy is fundamental for scientific computing in Python and is widely used in machine learning, data analysis, signal processing, and computational science. To use NumPy, install it using the following command: ... import numpy as np my_list = [1, 2, 3, 4, 5] # Convert list to a NumPy array arr = np.array(my_list) # Find indices of elements greater than 2 indices = np.where(arr > 2)[0] print("Indices of elements greater than 2:", indices)
🌐
W3Schools
w3schools.com › python › numpy › numpy_array_search.asp
NumPy Searching Arrays
The return value is an array: [1 2 3] containing the three indexes where 2, 4, 6 would be inserted in the original array to maintain the order. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com · If you want to report an error, or if you want to make a suggestion, send us an e-mail: help@w3schools.com · HTML Tutorial CSS Tutorial JavaScript Tutorial How To Tutorial SQL Tutorial Python Tutorial W3.CSS Tutorial Bootstrap Tutorial PHP Tutorial Java Tutorial C++ Tutorial jQuery Tutorial
🌐
Stack Abuse
stackabuse.com › python-check-if-array-or-list-contains-element-or-value
Python: Check if Array/List Contains Element/Value
February 27, 2023 - This approach has the same efficiency as the for loop, since the in operator, used like this, calls the list.__contains__ function, which inherently loops through the list - though, it's much more readable.
Find elsewhere
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)
🌐
GeeksforGeeks
geeksforgeeks.org › python › find-index-of-element-in-array-in-python
Find index of element in array in python - GeeksforGeeks
July 23, 2025 - Let's look into various other methods which we can use to find index of element in array in python is using a simple for loop. Table of Content · Using for loop · Using List Comprehension and enumerate() Using numpy for Arrays · For numerical arrays, numpy provides an efficient method using numpy.where().
🌐
DEV Community
dev.to › keploy › python-find-in-list-a-comprehensive-guide-4263
Python Find in List: A Comprehensive Guide - DEV Community
November 19, 2024 - Mutable: Lists can be modified after creation, allowing insertion, deletion, and updates to their elements. Versatile: They are used for various purposes, including storing datasets, managing queues, or representing collections of items. ... Python offers straightforward ways to perform the task of Python find in list, starting with simple methods like the in keyword and looping.
🌐
CodeRivers
coderivers.org › blog › python-find-in-array
Python Find in Array: A Comprehensive Guide - CodeRivers
February 22, 2026 - The following code finds all the indices of a target element in a list: my_list = [10, 20, 30, 20, 40] target = 20 occurrences = [index for index, value in enumerate(my_list) if value == target] print(occurrences) This code does the same thing as the previous example but in a more compact form. Multidimensional arrays in Python are represented as lists of lists.
🌐
W3Schools
w3schools.com › python › python_ref_list.asp
Python List/Array Methods
Note: Python does not have built-in support for Arrays, but Python Lists can be used instead.
🌐
C# Corner
c-sharpcorner.com › article › how-to-search-for-an-array-element-in-python
How to Search for an Array Element in Python
October 2, 2025 - Array element search is the process of determining whether a specific value exists in a collection and, optionally, retrieving its position. In Python, this typically involves lists, but the concepts extend to tuples, NumPy arrays, and other sequences.
🌐
W3Schools
w3schools.com › Python › ref_list_index.asp
Python List index() Method
Python DSA Lists and Arrays Stacks Queues Linked Lists Hash Tables Trees Binary Trees Binary Search Trees AVL Trees Graphs Linear Search Binary Search Bubble Sort Selection Sort Insertion Sort Quick Sort Counting Sort Radix Sort Merge Sort
🌐
Switowski
switowski.com › blog › find-item-in-a-list
Find Item in a List - Sebastian Witowski
August 27, 2020 - dividing their product by their greatest common divisor: 42 * 43 // math.gcd(42, 43) (Python 3.5 and above) Both versions will be an order of magnitude faster than my silly examples. Thanks to Dmitry for pointing this out! If we have a list of items that we want to check, we will use a "for loop" instead. I know that the number I'm looking for is smaller than 10 000, so let's use that as the upper limit: # find_item.py def for_loop(): for item in range(1, 10000): if (item % 42 == 0) and (item % 43 == 0): return item
🌐
W3Schools
w3schools.com › python › python_arrays.asp
Python Arrays
Remove List Duplicates Reverse a String Add Two Numbers · Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Training ... Note: Python does not have built-in support for Arrays, but Python Lists can be used instead.
🌐
Keploy
keploy.io › home › community › find elements in a python list: 7 methods with code examples
Find Elements in a Python List: 7 Methods with Code Examples | Keploy Blog
April 4, 2026 - List comprehension offers a flexible, and concise way to find elements in a list based on conditions. It’s really powerful and can be used in a variety of complex scenarios. Here’s just a single example of how we can do it: ... Python provides built-in functions like min() and max() to find the smallest and largest elements in a list, respectively.
🌐
Programiz
programiz.com › python-programming › methods › list › index
Python List index()
The index() method returns the index of the specified element in the list.