[英]Pairwise not being imported with itertools
I'm on python 3.8.2 and I've tried the following code我在 python 3.8.2 上,我尝试了以下代码
from itertools import pairwise
However, it returns但是,它返回
ImportError: cannot import name 'pairwise' from 'itertools' (unknown location)
I tried other variants of the same thing like import itertools
itertools.pairwise
, but it still gave me errors.我尝试了相同事物的其他变体,例如
import itertools
itertools.pairwise
,但它仍然给我错误。
I figured it could be a spelling mistake so I tried我认为这可能是拼写错误所以我尝试了
from itertools import *
print(dir())
But it wasn't there但它不在那里
['__builtins__', '__file__', '__name__', '__warningregistry__', 'accumulate', 'chain', 'combinations', 'combinations_with_replacement', 'compress', 'count', 'cycle', 'dropwhile', 'filterfalse', 'groupby', 'islice', 'permutations', 'product', 'repeat', 'starmap', 'takewhile', 'tee', 'zip_longest']
I even tried it on different devices and an online interpreter.我什至在不同的设备和在线翻译器上尝试过。
This pairwise only comes with Python 3.10+.这种成对仅随 Python 3.10+ 一起提供。 In previsous version, it is listed under Itertools Recipes section.
在之前的版本中,它列在Itertools Recipes部分下。
That's why you cannot find it.这就是为什么你找不到它。 Try to upgrade to latest version always.
尝试始终升级到最新版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.