이와 같이 좀 더 실용적인 패턴은 문자열 변형을 상위 레벨에서 쉽게 처리할 수 있다. 이렇게 해
서
clean
_
strings
함수는 재사용이 용이해졌다.
순차적 자료형에 대해 함수를 적용하는 내장 함수인
map
함수를 이용해서 함수를 인자로 사용
할 수도 있다.
In
[
176
]:
for x in map
(
remove
_
punctuation
,
states
):
.....:
print
(
x
)
Alabama
Georgia
Georgia
Georgia
FlOrIda
south carolina
West virginia
3.2.4
익명 함수
파이썬은 익명
anonymous
함수 혹은 람다
lambda
함수라고 하는 값을 반환하는 단순한 한 문장으로
이루어진 함수를 지원한다.
lambda
예약어로 정의하며, 이는 ‘익명 함수를 선언한다’라는 의미다.
def short
_
function
(
x
):
return x
*
2
equiv
_
anon
=
lambda x
:
x
*
2
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.