반응형
  • map 함수
    • map(함수, 순서가 있는 자료형)
    • map 의 결과는 map object 이기 때문에 사용하기 편한 list 형태로 변환한다.
def remove_blank(x):
  return x.strip()

items=[' mouse', ' monitor ']

items=list(map(remove_blank, items))

print(items)

# output
# ['mouse', 'monitor']

# 람다함수로 표기할 경우
items=list(map(lambda x:x.strip(), items))

 

  • filter 함수
    • filter(함수, 순서가 있는 자료형)
def func(x):
  return x < 0

print(list(filter(func, [-3, 0, 2, 7, -7])))

# output
# [-3, -7]

# 람다함수로 표현
print(list(filter(lambda x:x<0, [-3, 0, 2, 7, -7])))

 

728x90
반응형

'Development > Python' 카테고리의 다른 글

파이썬 문법 : method  (0) 2023.03.03
파이썬 문법 : class 속성들  (0) 2023.03.02
파이썬 문법 : 람다 함수  (0) 2023.02.27
파이썬 문법 : 키워드 가변 매개변수 kwargs  (0) 2023.02.27
파이썬 문법 : 튜플  (0) 2023.02.27

+ Recent posts