|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
from itertools import permutations
def find_all_nums(nums): max_len = len(nums) ans = [] temp = [] for i in range(1, max_len + 1): k = list(permutations(nums, i)) temp += k ## [0,1,1]처럼 리스트에 같은 수가 중복으로 있는 경우를 대비해 set 사용 result = list(set(temp)) for tuple in result: tot = '' for j in tuple: tot += str(j) ans.append(int(tot)) final = list(set(ans)) return final ## [0,1,1] 이 주어졌을때 만들 수 있는 모든 숫자 구하기 nums = [0,1,1] print(findAllNums(nums)) ## [0, 1, 101, 10, 11, 110] |
cs |
'프로그래밍 > 파이썬' 카테고리의 다른 글
| defaultdict() (0) | 2021.08.16 |
|---|