파이썬에서는 list 깊은 복사할 때는
import copy
, copy.deepcopy(list)
을 사용해야 한다.
import copy
def solution(array, commands):
answer = []
for in_command in commands:
cur_arr = copy.deepcopy(array)
cur_arr = sorted(cur_arr[in_command[0]-1:in_command[1]])
answer.append(cur_arr[in_command[2]-1])
return answer
잘짠 코드
def solution(array, commands):
return list(map(lambda x:sorted(array[x[0]-1:x[1]])[x[2]-1], commands))
def solution(array, commands):
answer = []
for command in commands:
i,j,k = command
answer.append(list(sorted(array[i-1:j]))[k-1])
return answer