combinations
作用:
可迭代对象iterable中选取r个单位进行组合
必要操作:
>>> import itertools
帮助查看:
>>> help(itertools)
或 单独查看某个方法(函数)
>>> help(itertools.combinations)
方法(函数):
>>> from itertools import combinations >>> data = [1, 2, 3, 4] >>> result = list(combinations(data , 2)) >>> print(result ) [(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)]