습관처럼

python - map,filter,reduce: 조건 변형 본문

Language/python

python - map,filter,reduce: 조건 변형

dev.wookii 2019. 12. 9. 17:59

파이썬에서 리스트의 결과를 특정 조건에따라 원소별로 변환하거나, 필터를 사용해 걸러내거나, 연산하는방법으로 map,filter,reduce 를 사용가능하다.

이 세가지 클래스는 함수를 매개변수로 받아 결과를 반환하는데, 이때 람다함수(lambda)를 자주 사용합니다.

 

우선 리스트를 만들고 각각 map,filter,reduce를 사용해봤습니다.

 

map,filter,reduce

reduce 함수는 매개 변수로 function, iterable[, initializer] 를 갖는다는 점을 주의해주세요~


>>run

[1, 4, 9, 16]
['1', '2', '3', '4', '5']
[1, 3]
24

Process finished with exit code 0

'Language > python' 카테고리의 다른 글

python - 내장함수  (0) 2019.12.22
python - set :집합  (0) 2019.12.21
python - append 그리고 extend  (0) 2019.12.21
python - List  (0) 2019.12.21
python - combinations,permutations:순열과 조합  (0) 2019.12.08