Open this example in the interactive library
Source code
from itertools import combinations
print(list(combinations('ABC', 2)))Sample output
[('A', 'B'), ('A', 'C'), ('B', 'C')]
Generate combinations. A self-contained example using the Python standard library.
Open this example in the interactive library
from itertools import combinations
print(list(combinations('ABC', 2)))[('A', 'B'), ('A', 'C'), ('B', 'C')]