Python中的itertools.permutations
程序员文章站
2024-02-12 13:22:52
...
通俗地讲,就是返回可迭代对象的所有数学全排列方式。
Python 2.7.12 (default, Nov 20 2017, 18:23:56)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from itertools import permutations
>>> permutations(['a', 'b', 'c'])
<itertools.permutations object at 0x7ff7b1411890>
>>> for item in permutations(['a', 'b', 'c']):
... print item
...
('a', 'b', 'c')
('a', 'c', 'b')
('b', 'a', 'c')
('b', 'c', 'a')
('c', 'a', 'b')
('c', 'b', 'a')
>>> for i in itertools.permutations('123', 2):
... print i
...
('1', '2')
('1', '3')
('2', '1')
('2', '3')
('3', '1')
('3', '2')
>>> itertools.permutations('123', 2)
<itertools.permutations object at 0x7f5addcca8f0>
上一篇: vue的静态路由和动态路由
下一篇: python中的排列-itertools