本文介紹了我在 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()的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!