繁体   English   中英

成对不使用 itertools 导入

[英]Pairwise not being imported with itertools

我在 python 3.8.2 上,我尝试了以下代码

from itertools import pairwise

但是,它返回

ImportError: cannot import name 'pairwise' from 'itertools' (unknown location)

我尝试了相同事物的其他变体,例如import itertools itertools.pairwise ,但它仍然给我错误。

我认为这可能是拼写错误所以我尝试了

from itertools import *

print(dir())

但它不在那里

['__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']

我什至在不同的设备和在线翻译器上尝试过。 在线翻译的截图,因为这听起来很疯狂

这种成对仅随 Python 3.10+ 一起提供。 在之前的版本中,它列在Itertools Recipes部分下。

这就是为什么你找不到它。 尝试始终升级到最新版本。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM