简体   繁体   中英

Pairwise not being imported with itertools

I'm on python 3.8.2 and I've tried the following code

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.

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+. In previsous version, it is listed under Itertools Recipes section.

That's why you cannot find it. Try to upgrade to latest version always.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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