7. 파이썬 함수형 프로그래밍: map · filter · zip · reduce
map, filter, zip, reduce 함수와 람다(lambda)로 데이터 처리 흐름을 간결하게 만드는 방법을 예제 중심으로 정리했습니다.1. map() — 각 요소에 함수 적용nums = [1, 2, 3, 4, 5]squares = list(map(lambda x: x**2, nums))print(squares) # [1, 4, 9, 16, 25]map()은 리스트나 튜플 등 이터러블의 각 요소에 함수를 순차적으로 적용하여 새로운 맵 객체를 반환합니다2. filter() — 조건에 맞는 요소 필터링numbers = [1,2,3,4,5,6]evens = list(filter(lambda x: x % 2 == 0, numbers))print(evens) # [2, 4, 6]filter()는 각 요..
2025. 7. 12.