To find the size of a list in Python, use len(): len(["Austin", "Denver", "Seattle"]) returns 3, the number of elements. The same call gives the length of a list, and it’s instant because Python stores the count with the list:
cities = ["Austin", "Denver", "Seattle", "Boston", "Tampa"]
len(cities) # 5
“Size” can also mean memory, so I’ve covered both meanings below, each with output from Python 3.12.5.
You’ll see len() with empty lists, nested lists, len vs count(), why map objects have no length, the size of a list in bytes, and why len() costs the same for any list.
Find the number of elements in a list with len()
len() returns how many items the list holds. An empty list has length 0, which is why if not orders: works as an empty check:
cities = ["Austin", "Denver", "Seattle", "Boston", "Tampa"]
print(len(cities))
print(len([]))
orders = []
if not orders: # the usual empty check
print("no orders yet")
print(cities[len(cities) - 1], cities[-1]) # last item two ways
Output:
5
0
no orders yet
Tampa Tampa

len(cities) - 1 is the last index; -1 is shorter. More ways to grab the end are in getting the last element of a list.
Find the length of a nested list
len() only counts top-level items, so an inner list counts as one. Add up the inner lengths, or recurse for deeper nesting:
regions = [["Austin", "Dallas", "Houston"], ["Denver"], ["Tampa", "Miami"], []]
print("top-level items:", len(regions))
print("cities in total:", sum(len(r) for r in regions))
print("lengths:", [len(r) for r in regions])
def deep_len(items):
return sum(deep_len(x) if isinstance(x, list) else 1 for x in items)
print("deep count:", deep_len([1, [2, 3, [4, 5]], 6]))
Output:
top-level items: 4
cities in total: 6
lengths: [3, 1, 2, 0]
deep count: 6

Empty inner lists still count as top-level items. The same rules apply to tuples, as shown in finding the length of a tuple.
len() vs count(), and why map objects have no length
count(x) tells you how often one value appears, which is a different question. Lazy objects like map and generators don’t know their length at all:
ratings = [5, 4, 5, 3, 5, 4, 1]
print("len:", len(ratings), "| count(5):", ratings.count(5), "| distinct:", len(set(ratings)))
words = ["Python", "list", "size"]
print("items:", len(words), "| characters:", sum(len(w) for w in words))
squares = map(lambda n: n * n, range(4))
try:
len(squares)
except TypeError as err:
print("TypeError:", err)
print(len(list(squares)))
Output:
len: 7 | count(5): 3 | distinct: 4
items: 3 | characters: 14
TypeError: object of type 'map' has no len()
4

Converting with list() uses the map up, so keep the list. Counting every value at once is covered in counting the frequency of elements in a list.
How do I get the size of a list in bytes?
sys.getsizeof() reports the memory of the list object itself: its header plus one pointer per slot. It doesn’t include the objects the list points to:
import sys
small = [1, 2, 3]
names = ["Emily Carter" * 100, "James Wilson"]
print(len(small), "items,", sys.getsizeof(small), "bytes for the list object")
print(len(names), "items,", sys.getsizeof(names), "bytes for the list object")
print("plus the strings:", sum(sys.getsizeof(s) for s in names), "bytes")
growing = []
for i in range(10):
growing.append(i)
print(len(growing), sys.getsizeof(growing), end=" | ")
print()
Output:
3 items, 88 bytes for the list object
2 items, 72 bytes for the list object
plus the strings: 1294 bytes
1 88 | 2 88 | 3 88 | 4 88 | 5 120 | 6 120 | 7 120 | 8 120 | 9 184 | 10 184 |

Lists reserve extra slots as they grow, so memory goes up in jumps. If you know the size ahead of time, see initializing a list of size N.
Is len() slow on large lists?
No. The count is stored on the list, so len() doesn’t loop. Ten items and a million items take about the same time:
import timeit
for n in (10, 1_000_000):
data = list(range(n))
t = min(timeit.repeat("len(data)", globals={"data": data}, number=1_000_000, repeat=3))
print(f"len() on {n:>9,} items: {t * 1000:.1f} ms per million calls")
Output:
len() on 10 items: 19.7 ms per million calls
len() on 1,000,000 items: 29.7 ms per million calls
The timings vary by machine and wobble a little, but they don’t grow a million-fold with the list. For strings, the same holds, as covered in getting the length of a string in Python.
List size methods compared
| Question | Code |
|---|---|
| How many elements? | len(lst) |
| Is it empty? | if not lst: |
| Total in nested lists | sum(len(x) for x in lst) |
| How often does x appear? | lst.count(x) |
| How many distinct values? | len(set(lst)) |
| Memory of the list object | sys.getsizeof(lst) |
Here’s where to go next with lists:
- Count occurrences in a Python list
- Find duplicates in a Python list
- Remove the last element from a list
- Get the length of a Python dictionary
Frequently asked questions
How do I find the size of a list in Python?
Use len(my_list). It returns the number of elements.
What’s the difference between list size and length?
In everyday Python they mean the same thing: len(). Size in bytes is sys.getsizeof().
Does len() count items inside nested lists?
No, only top-level items. Use sum(len(x) for x in nested) for one level.
Why does len() fail on a map object?
map and generators are lazy and don’t know their length. Convert with list() first.
Is len() O(1) in Python?
Yes. Lists store their length, so len() takes the same time for any size.
Where is len() documented?
See len() in the Python docs.

Bijay Kumar is a 13-time Microsoft MVP with more than 18 years in software development, and the founder of Python Guides and TSinfo Technologies. He started out building .NET and SharePoint solutions at HP, TCS and KPIT before moving into Python, machine learning and AI, and he also builds web apps with TypeScript and React. He writes the tutorials here himself, and every example is run before publishing so you see the real output. More about Bijay · Microsoft MVP profile · LinkedIn