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
- 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 (n-choose-k) combinations of length n
- 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
- a pythonic way of doubling consecutive binary bits [closed]
- Return in Recursive Function
- Numpy matrix to array
- Python argparse ignore unrecognised arguments
- Python Paramiko – Run command
- Python Pandas Conditional Sum with Groupby
- Using conditional to generate new column in pandas dataframe
- Certifacte verify failed: certificate has expired (_ssl.c:1108)
- Change default Python version from 2.4 to 2.6
- How to split by comma and strip white spaces in Python?
- How can I dynamically create class methods for a class in python [duplicate]
- Converting List Comprehensions to For Loops in Python
- Make the Python json encoder support Python’s new dataclasses
- Eliminating warnings from scikit-learn [duplicate]
- Adapt an iterator to behave like a file-like object in Python