Find the Length of a List
You need to know how many elements there are in a list.
Use the len Python function. For example:
>>> a = [34, ‘Fred’, 12, False, 72.3] >>> len(a) 5 |
Discussion
The len command also works on strings (Recipe 5.13).
See Also
All the recipes between Recipes 6.1 and 6.11 involve the use of lists.