map(function, iterable)
function : 각 요소에 적용할 함수
iterable : 함수를 적용할 데이터 집합
각 요소에 대해 function 함수를 적용한 결과를 새로운 iterator로 반환
예시
def square(x):
return x**2
numbers = [1, 2, 3, 4, 5]
squared_numbers = map(square, numbers)
print(list(squared_numbers) # [1, 4, 9, 16, 25]
예시2 - 여러 개의 객체 입력
def add(x, y):
return x + y
numbers1 = [1, 2, 3, 4, 5]
numbers2 = [10, 20, 30, 40, 50]
added_numbers = map(add, numbers1, numbers2)
print(list(added_numbers)) # [11, 22, 33, 44, 55]