Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # recursion_combinations.py
- t = [1,2,3,4,5]
- def combinations(array, tuple_length, prev_array=[]):
- if len(prev_array) == tuple_length:
- return [prev_array]
- combs = []
- for i, val in enumerate(array):
- prev_array_extended = prev_array[:]
- prev_array_extended.append(val)
- combs += combinations(array[i+1:], tuple_length, prev_array_extended)
- return combs
- ttt = combinations(t, 3)
- ttt.sort()
- for z in ttt:
- print(z)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement