create all combinations from three elements of a list in python

You can use the combinations() function from the itertools module to generate all possible combinations of three elements from a given list. Here's an example:

main.py
import itertools

my_list = ['a', 'b', 'c', 'd', 'e']
combos = itertools.combinations(my_list, 3)

for combo in combos:
    print(combo)
137 chars
8 lines

This will output all possible combinations of three elements from the list ['a', 'b', 'c', 'd', 'e'].

main.py
('a', 'b', 'c')
('a', 'b', 'd')
('a', 'b', 'e')
('a', 'c', 'd')
('a', 'c', 'e')
('a', 'd', 'e')
('b', 'c', 'd')
('b', 'c', 'e')
('b', 'd', 'e')
('c', 'd', 'e')
160 chars
11 lines

gistlibby LogSnag