Object of type ‘map’ has no len() in Python 3

In Python 3, map returns a map object not a list:

>>> L = map(str, range(10))
>>> print(L)
<map object at 0x101bda358>
>>> print(len(L))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: object of type 'map' has no len()

You can convert it into a list then get the length from there:

>>> print(len(list(L)))
10

Leave a Comment