Combinations method in Itertools Module
suggest changeitertools.combinations will return an iterator of the k-combination sequence of a list.
In other words: It will return an iterator of tuples of all the possible k-wise combinations of the input list.
For Example:
If you have a list:
Output:
[(1, 2), (1, 3), (1, 4), (1, 5), (2, 3), (2, 4), (2, 5), (3, 4), (3, 5), (4, 5)]
The above output is a list of tuples of all the possible pair-wise combinations of the input list a.
You can also find all the 3-combinations:
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents