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

北战南征 提交于 2019-11-27 22:43:30

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!