“ map”类型的对象在Python 3中没有len()

索尼娅

我对Python 3有问题。我有Python 2.7代码,此刻我正在尝试对其进行更新。我得到错误:

TypeError:“地图”类型的对象没有len()

在这一部分:

str(len(seed_candidates))

在这样初始化之前:

seed_candidates = map(modify_word, wordlist)

那么,有人可以解释我该怎么做吗?

(编辑:以前,此代码示例是错误的,因为它使用set代替map。现在已更新。)

特里:

在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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Map对象在Python 3中没有len()

类型错误:“int”类型的对象在 python 中没有 len()

python中的错误-类型为'NoneType'的对象没有len()

类型“ datetime.date”的对象在python中没有len()

TypeError:尝试将CSV插入Python 3中的SQL Server数据库时,类型为“ map”的对象没有len()

Python 3.5 TypeError 上的 Gensim 1.0.1:“map”类型的对象没有 len()?

类型为“ Response”的对象在DRF中没有len()

类型为'ModelBase'的/ products /对象中的TypeError没有len()

Python 2-> 3:类型为'zip'的对象没有len()

类型错误:“~~~~”类型的对象没有 len()

TypeError:在Beautifulsoup和Selenium Python中类型为'NoneType'的对象没有len()

TypeError:“ int”类型的对象在atom编辑器上的python中没有len()

python-fuzzywuzzy错误-float类型的对象没有len

类型为“ float”的Python对象没有len()

TypeError:类型'int'的对象没有len()-Python / Pygame

Python - TypeError:“Cell”类型的对象没有 len()

“WebElement”类型的对象没有 len() - Python Selenium

'generator'类型的对象没有len()

'ListedColormap'类型的对象没有len()

TypeError:“ WebElement”类型的对象没有len()

'Activation'类型的对象没有len()

WebElement类型的Selenium对象没有len()

'_Task'类型的对象没有len()错误

类型错误:“ID3TimeStamp”类型的对象没有 len()

对于我在range(len(val))中:TypeError:类型为'numpy.float64'的对象没有len()

类型错误:“文本”类型的对象没有 len()

类型错误:“响应”类型的对象没有 len() [BeautifulSoup]

类型错误:“EmailMultiAlternatives”类型的对象没有 len()

在函数中返回 None:TypeError:“NoneType”类型的对象没有 len()