itertools
can do this:
import itertools
for comb in itertools.combinations([1, 2, 3, 4], 3):
print(comb)
Outputs:
(1, 2, 3)
(1, 2, 4)
(1, 3, 4)
(2, 3, 4)
More Related Contents:
- How to get all possible combinations of a list’s elements?
- All combinations of a list of lists
- Making all possible combinations of a list
- Find all combinations of a list of numbers with a given sum
- How to get all combinations of length n in python
- Statistics: combinations in Python
- Generating all possible combinations of a list, “itertools.combinations” misses some results
- Numpy: efficient way to generate combinations from given ranges
- Get all possible (2^N) combinations of a list’s elements, of any length
- How to generate all combination from values in dict of lists in Python
- python all possible combinations of 0,1 of length k [duplicate]
- How do I compute all possibilities for an array of numbers/bits (in python, or any language for that matter)
- Finding Combinations to the provided Sum value
- Given a list of elements in lexicographical order (i.e. [‘a’, ‘b’, ‘c’, ‘d’]), find the nth permutation – Average time to solve?
- counting combinations and permutations efficiently
- Empty string python zapier
- “pip install unroll”: “python setup.py egg_info” failed with error code 1
- Freezing/Hanging tkinter GUI in waiting for the thread to complete
- How to expand a list to function arguments in Python [duplicate]
- Pipe subprocess standard output to a variable [duplicate]
- selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities with Firefox 46 through Selenium
- requests: how to disable / bypass proxy
- Python: How to show matplotlib in flask [duplicate]
- PyQt5 QTextBrowser – setText – Alignment issue?
- Mock attributes in Python mock?
- Convert string into datetime.time object
- What is the correct syntax for ‘else if’?
- Is making in-place operations return the object a bad idea?
- How do you change the value of one attribute by changing the value of another? (dependent attributes)
- Pythonic way to convert a dictionary into namedtuple or another hashable dict-like?