Python combinations generator

combinations(n,r) generator returns all conbinations from the data elements. Where: n: list, no duplication in its elements r: subset

>>> from itertools import *
>>> data = [2,6,9,3]
>>> x = combinations(data,2)
>>> for i in x:
>>> print (i)
(2, 6)
(2, 9)
(2, 3)
(6, 9)
(6, 3)
(9, 3)




















endmemo.com © 2024  | Terms of Use | Privacy | Home