Home  >  Article  >  Backend Development  >  Python 的库函数里有没有现成的全排列函数?

Python 的库函数里有没有现成的全排列函数?

WBOY
WBOYOriginal
2016-06-06 16:24:341638browse

回复内容:

这个就行
>>> for i in itertools.permutations('abcd',4):
print ''.join(i) itertools里就有…全排列就靠permutation了,参数是个可迭代量,返回值是个迭代器。

当然也有部分排列、组合、部分组合之类的。
<code class="language-text">print list(itertools.combinations(['a','b','c'],2))
[('a', 'b'), ('a', 'c'), ('b', 'c')]
</code>
在itertools模块 里面
product函数 我做个笔记,差点又忘了,那些用模块的啊,真是图样图森破
全排列可以这样那个写
[[x,y,z] for x in [1,2,3] for y in ['a','b','c'] for z in ['o','r','z']]
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn