在Python 3中,
map返回的地图对象不是
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()
您可以将其转换为列表,然后从那里获取长度:
>>> print(len(list(L)))10



