I can#39;t find imap() in itertools in Python(我在 Python 的 itertools 中找不到 imap())
问题描述
我有一个问题想用 itertools.imap() 解决.但是,当我在 IDLE shell 中导入 itertools 并调用 itertools.imap() 后,IDLE shell 告诉我 itertools 没有属性 imap.怎么了?
I have a problem that I want to solve with itertools.imap(). However, after I imported itertools in IDLE shell and called itertools.imap(), the IDLE shell told me that itertools doesn't have attribute imap. What's going wrong?
>>> import itertools
>>> dir(itertools)
['__doc__', '__loader__', '__name__', '__package__', '__spec__', '_grouper', '_tee', '_tee_dataobject', 'accumulate', 'chain', 'combinations', 'combinations_with_replacement', 'compress', 'count', 'cycle', 'dropwhile', 'filterfalse', 'groupby', 'islice', 'permutations', 'product', 'repeat', 'starmap', 'takewhile', 'tee', 'zip_longest']
>>> itertools.imap()
Traceback (most recent call last):
File "<pyshell#13>", line 1, in <module>
itertools.imap()
AttributeError: 'module' object has no attribute 'imap'
推荐答案
itertools.imap() 在 Python 2 中,但不在 Python 3 中.
itertools.imap() is in Python 2, but not in Python 3.
实际上,该函数在 Python 3 中被移到了 map 函数中,如果你想使用旧的 Python 2 地图,你必须使用 list(map())代码>.
Actually, that function was moved to just the map function in Python 3 and if you want to use the old Python 2 map, you must use list(map()).
这篇关于我在 Python 的 itertools 中找不到 imap()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:我在 Python 的 itertools 中找不到 imap()
基础教程推荐
- 比较两个文本文件以找出差异并将它们输出到新的文本文件 2022-01-01
- 对多索引数据帧的列进行排序 2022-01-01
- 在 Django Admin 中使用内联 OneToOneField 2022-01-01
- Kivy 使用 opencv.调整图像大小 2022-01-01
- 在 Python 中将货币解析为数字 2022-01-01
- Python 中是否有任何支持将长字符串转储为块文字或折叠块的 yaml 库? 2022-01-01
- kivy 应用程序中的一个简单网页作为小部件 2022-01-01
- matplotlib 设置 yaxis 标签大小 2022-01-01
- Python,确定字符串是否应转换为 Int 或 Float 2022-01-01
- 究竟什么是“容器"?在蟒蛇?(以及所有的 python 容器类型是什么?) 2022-01-01
