Get unique combinations of elements from a python list [duplicate] Get unique combinations of elements from a python list [duplicate] python python

Get unique combinations of elements from a python list [duplicate]


You need itertools.combinations:

>>> from itertools import combinations>>> L = [1, 2, 3, 4]>>> [",".join(map(str, comb)) for comb in combinations(L, 3)]['1,2,3', '1,2,4', '1,3,4', '2,3,4']