파이썬 filter, lambda를 이용한 새로운 리스트 만들기

728x90
now_list = [1, 2, 3, 4, 5, 6, 7]
except_list = [1, 2, 3, 4]
new_list = list(filter(lambda l: l not in except_list, now_list))
print(new_list) # [5, 6, 7]

now_list에서 except_list에 있는 값을 제거 후 새로운 new_list를 만든다.

반응형