Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from itertools import combinations
- def dec_tree(digit):
- res = [tuple(x for x in range(digit))]
- while len(min(res)) != 1:
- new_list = []
- for item in res:
- new_list.extend(combinations(item, len(min(res)) - 1))
- res.extend(new_list)
- return sorted([list(x) for x in set(sorted(res))])
- assert dec_tree(2) == sorted([[0], [1], [0,1]])
- assert dec_tree(3) == sorted([[0], [1], [2], [0,1], [0,2], [1,2], [0,1,2]])
- assert dec_tree(4) == sorted(
- [[0], [1], [2], [3], [0, 1], [0, 2], [0, 3], [1, 2],
- [1, 3], [2, 3], [0, 1, 2], [0, 1, 3], [0, 2, 3], [1, 2, 3], [0, 1, 2, 3]])
Advertisement
Add Comment
Please, Sign In to add comment