#함수
def flatten(data):
output = []
for i in data:
print(i)
if type(i) == list:
output += flatten(i)
else:
output.append(i)
return output
example = [[1,2,3],[4,5,6],7,[8,9]]
print("원본:", example)
print("변환:",flatten(example))
원본: [[1, 2, 3], [4, 5, 6], 7, [8, 9]]
[1, 2, 3]
1
2
3
[4, 5, 6]
4
5
6
7
[8, 9]
8
9
변환: [1, 2, 3, 4, 5, 6, 7, 8, 9]
i = 2
ma = 10
to = 100
memo = {}
def table_sit(lef_p,sit_p):
key = str([lef_p,sit_p])
#조건 종료
if key in memo:
return memo[key]
if lef_p < 0:
return 0
if lef_p == 0:
return 1
#재귀처리
count = 0
for i in range(sit_p,ma +1):
count += table_sit(lef_p - i, i)
# 메모화 처리
memo[key] = count
# 종료
return count
print(table_sit(100,2))
437420