Python - itertools.combinations()


Python tip:

You can generate all combinations of elements from an iterable of length n by using combinations from itertools.

For example, you can generate all possible match pairs 👇

from itertools import combinations

players = ["John", "Daisy", "Marry", "Bob"]

print(list(combinations(players, 2)))

"""
[
    ('John', 'Daisy'),
    ('John', 'Marry'),
    ('John', 'Bob'),
    ('Daisy', 'Marry'),
    ('Daisy', 'Bob'),
    ('Marry', 'Bob'),
]
"""