当前位置:网站首页>Itemtools permutation

Itemtools permutation

2022-06-22 07:34:00 Muxiatong

python Permutation and combination can be used itertools library

array

from l Choose from 3 Elements , Arrange , It is allowed to select repeated

from itertools import product
l = [1, 2, 3]
print list(product(l, repeat=3))

Combine

from l Choose from 3 The elements are combined , No duplicate elements selected

from itertools import combinations
l = [1, 2, 3, 4, 5]
print (list(combinations(l, 3)))

Permutation and combination

from s Choose from 4 Arrange and combine elements , No repeating elements will be selected

s = 'K Q 6 J A'.split()
from itertools import permutations
num_orders = list(permutations(s, 4))
print(num_orders)

原网站

版权声明
本文为[Muxiatong]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206220733439342.html