This saves the data in a list of lists.

text = open("filetest.txt", "r")
data = [ ]
for line in text:
    data.append( line.strip().split() )

print "number of lines ", len(data)
print "number of columns ", len(data[0])

print "element in first row column two ", data[0][1]
Answer from Javier Castellanos on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-ways-to-find-length-of-list
How To Find the Length of a List in Python - GeeksforGeeks
May 2, 2025 - len() function is a built-in Python function and it's the simplest and most efficient way to find the length of a list in Python.
๐ŸŒ
DataCamp
datacamp.com โ€บ tutorial โ€บ python-list-size
Python List Size: 8 Different Methods for Finding the Length of a List in Python | DataCamp
February 7, 2024 - The len() function is the most straightforward approach to ascertain the size of a list. It is not only concise but also highly efficient, making it the go-to method in most cases.
Discussions

How to determine the size of all combined elements in a list of lists
This will loop through everything once, but it'll handle any depth (up to recursion limits): from collections.abc import Sequence def len_items(items): """Return the length of all nested iterables.""" return sum( len_items(item) if isinstance(item, Sequence) else 1 for item in items ) More on reddit.com
๐ŸŒ r/learnpython
26
70
December 31, 2020
How do I get the number of elements in a list (length of a list) in Python? - Stack Overflow
Lists and other similar builtin objects with a "size" in Python, in particular, have an attribute called ob_size, where the number of elements in the object is cached. So checking the number of objects in a list is very fast. But if you're checking if list size is zero or not, don't use len - instead, put the list in a boolean context - it is treated as False if empty, and True if non-empty. ... Return the length ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
How to Find All Subsequences of a String?
def all_subs(word: str) -> list: substring = [] for idx in range(len(word)): string_portion = word[:idx + 1] # <-- w, wo, wor, word #string_portion = word[idx:] # <-- word, ord, rd, d substring.append(string_portion) print(string_portion) return substring word[from:to] = slice of the original word, from and to being numerical values between 0 (zero) and the length of the word - 1. If from = 0, it can be omitted word[:to], python assumes that its zero If to = length, it can be omitted word[from:] Hope it helps More on reddit.com
๐ŸŒ r/learnpython
4
3
October 25, 2018
[Python] How do I slice and print half of a string regardless of how long it is?
string[0:len(string)//2] More on reddit.com
๐ŸŒ r/learnprogramming
4
1
September 3, 2018
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ find-the-length-of-a-list-in-python
How to find the length of a list in Python | DigitalOcean
July 25, 2025 - How to find the length of a list in Python using the len() function. Includes examples, edge cases, and tips for working with nested or dynamic lists.
๐ŸŒ
Edureka
edureka.co โ€บ blog โ€บ python-list-length
How to Get the Length of List in Python? | Edureka
November 27, 2024 - The len() method is one of the easiest ways to find the length of list in Python. This is the most conventional technique adopted by all programmers.
Find elsewhere
๐ŸŒ
Cherry Servers
cherryservers.com โ€บ home โ€บ blog โ€บ cloud computing โ€บ how to get the length of a list in python
How to Get the Length of a List in Python | Cherry Servers
November 7, 2025 - This tutorial has walked you through five different methods on how to find the length of a list in Python: len(), for loop, length_hint(), __len__() special function and the NumPy library.
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ python-list-length-how-to-get-the-size-of-a-list-in-python
Python List Length โ€“ How to Get the Size of a List in Python
March 3, 2022 - The code snippet below shows how to use the len() function to get the length of a list: demoList = ["Python", 1, "JavaScript", True, "HTML", "CSS", 22] sizeOfDemoList = len(demoList) print("The length of the list using the len() method is: " ...
๐ŸŒ
Carmatec
carmatec.com โ€บ home โ€บ finding the length of a list in python with examples
Finding the Length of a List in Python With Examples
December 31, 2024 - In this article, weโ€™ll explore the len() function in detail, along with examples and alternative approaches for measuring list length. The len() function is a built-in Python function that returns the number of items in an object.
๐ŸŒ
iO Flood
ioflood.com โ€บ blog โ€บ python-length-of-list
Finding the Length of a List in Python (With Examples)
August 21, 2024 - Then, we used the len() function, which returned the number of elements in the list, which is 5. The len() function is a straightforward and efficient way to find the length of a list in Python.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ gloss_python_list_length.asp
Python List Length
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
๐ŸŒ
Note.nkmk.me
note.nkmk.me โ€บ home โ€บ python
Get the Size (Length, Number of Items) of a List in Python | note.nkmk.me
August 24, 2023 - In Python, you can get the size (length, number of items) of a list using the built-in len() function. Built-in Functions - len() โ€” Python 3.11.3 documentation Get the size of a list with len() Get t ...
๐ŸŒ
Hostman
hostman.com โ€บ tutorials โ€บ how to get the length of a list in python
How to Find the Length of a List in Python: Quick Guide | Hostman
July 17, 2025 - Country_list = ["The United States ... length in Python with a for loop. The idea is to traverse the entire list while incrementing a counter by 1 on each iteration....
Price ย  $
Call ย  +1 844 286 2130
Address ย  1999 Harrison St 1800 9079, 94612, Oakland
๐ŸŒ
Great Learning
mygreatlearning.com โ€บ blog โ€บ it/software development โ€บ how to find length of list in python
How to Find Length of List in Python
June 20, 2022 - Using a loop (less common but illustrates concepts): You can count elements by iterating through the list. Letโ€™s look at each one. The len() function is a built-in Python function. It takes an object as an argument and returns its length (the ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ find-size-of-a-ist-in-python
How to Find Length of a list in Python - GeeksforGeeks
July 11, 2025 - The length of a list means the number of elements it contains. In-Built len() function can be used to find the length of an object by passing the object within the parentheses. Here is the Python example to find the length of a list using len().
Top answer
1 of 11
2991

The len() function can be used with several different types in Python - both built-in types and library types. For example:

>>> len([1, 2, 3])
3
2 of 11
323

How do I get the length of a list?

To find the number of elements in a list, use the builtin function len:

items = []
items.append("apple")
items.append("orange")
items.append("banana")

And now:

len(items)

returns 3.

Explanation

Everything in Python is an object, including lists. All objects have a header of some sort in the C implementation.

Lists and other similar builtin objects with a "size" in Python, in particular, have an attribute called ob_size, where the number of elements in the object is cached. So checking the number of objects in a list is very fast.

But if you're checking if list size is zero or not, don't use len - instead, put the list in a boolean context - it is treated as False if empty, and True if non-empty.

From the docs

len(s)

Return the length (the number of items) of an object. The argument may be a sequence (such as a string, bytes, tuple, list, or range) or a collection (such as a dictionary, set, or frozen set).

len is implemented with __len__, from the data model docs:

object.__len__(self)

Called to implement the built-in function len(). Should return the length of the object, an integer >= 0. Also, an object that doesnโ€™t define a __nonzero__() [in Python 2 or __bool__() in Python 3] method and whose __len__() method returns zero is considered to be false in a Boolean context.

And we can also see that __len__ is a method of lists:

items.__len__()

returns 3.

Builtin types you can get the len (length) of

And in fact we see we can get this information for all of the described types:

>>> all(hasattr(cls, '__len__') for cls in (str, bytes, tuple, list, 
                                            range, dict, set, frozenset))
True

Do not use len to test for an empty or nonempty list

To test for a specific length, of course, simply test for equality:

if len(items) == required_length:
    ...

But there's a special case for testing for a zero length list or the inverse. In that case, do not test for equality.

Also, do not do:

if len(items): 
    ...

Instead, simply do:

if items:     # Then we have some items, not empty!
    ...

or

if not items: # Then we have an empty list!
    ...

I explain why here but in short, if items or if not items is more readable and performant than other alternatives.

๐ŸŒ
4Geeks
4geeks.com โ€บ how-to โ€บ how-to-get-python-list-length
How to Get the Length of a List in Python?
July 16, 2025 - The len() function returns the number of items in the list. In this case, list_length will be 5. The len() function is not only straightforward but also highly efficient, making it ideal for any list size.
๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ python โ€บ find the length of a list in python
Find the Length of a List in Python - Spark By {Examples}
May 31, 2024 - How to find or get the length of a list in Python? To find the length of a list in Python use the len(), naive, length_hint(), sum(), collections, and enumerate() functions. The len() function can be used to get the length of various built-in ...