itertools.combinations and itertools.permutations in python

itertools.combinations

1. The combination(iterable,r) method of the python itertools module can create an iterator that returns all subsequences of length r in the iterable, and the items in the returned subsequence are sorted in the order of the input iterable.

import itertools
list1 = ['a',7,'n',1]
list2 = list(itertools.combinations(list1,2))
print(list2)

insert image description here
2. The permutations in the itertools module are all arranged

import itertools
list3 = list(itertools.permutations('afv'))
print(list3)

insert image description here
Thank you for your support. Your one-click three-connection is the biggest driving force for Ganggang students!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324322681&siteId=291194637