gpt4 book ai didi

python - 如何安装 itertools 包?

转载 作者:行者123 更新时间:2023-12-03 23:05:43 26 4
gpt4 key购买 nike

我想试试permutations来自 itertools 的函数模块。但是每次我尝试实现它时,我都会收到以下错误:
代码:

from itertools import permutations

txt=permutations('SKIN')
print(txt)
输出:
<itertools.permutations object at 0x7fee48665950>
我尝试使用命令 pip install itertools在我的命令提示符下,但我不断收到错误消息:
ERROR: Could not find a version that satisfies the requirement itertools (from versions: none)
ERROR: No matching distribution found for itertools
如何安装软件包?

最佳答案

itertools 是一个内置模块,无需安装:

Help on module itertools:

NAME
itertools - Functional tools for creating and using iterators.

FILE
/usr/lib64/python2.7/lib-dynload/itertoolsmodu
permutations(<iterable>)返回一个生成器,它产生可迭代中元素的连续 r 长度排列:
>>> type(txt)
<type 'itertools.permutations'>

>>> dir(txt)
['__class__', '__delattr__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__iter__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'next']
所需排列列表:
list_perms = [ "".join(i) for i in permutations("SKIN")]

# ['SKIN', 'SKNI', 'SIKN', 'SINK', 'SNKI', 'SNIK', 'KSIN', 'KSNI', 'KISN', 'KINS', 'KNSI', 'KNIS', 'ISKN', 'ISNK', 'IKSN', 'IKNS', 'INSK', 'INKS', 'NSKI', 'NSIK', 'NKSI', 'NKIS', 'NISK', 'NIKS']

关于python - 如何安装 itertools 包?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62874228/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com