map,filter
map과 filter값을 받아오기위해서는
방법이
for루프
list()함수
이 방법밖에 없는건가요??
그리고 map,filter인자에는 list만 들어갈수있나요?? 딕셔너리,set, 튜플등은 안되나요?
답변 1
0
안녕하세요 남기정님,
아래의 예제는 Lambda를 사용해서 쓸수 있는 방법에 대해 보실 수 있습니다.
# Sample list of integers
numbers = [1, 2, 3, 4, 5]
# Using map with a lambda function to square each element
squared_numbers = map(lambda x: x**2, numbers)
# Convert the map object to a list to see the results
result = list(squared_numbers)
# Print the squared numbers
print(result)또한 Dictionary나 Set도 사용 가능합니다.
# Sample dictionary
my_dict = {'a': 1, 'b': 2, 'c': 3}
# Using map with a lambda function to square each value in the dictionary
squared_keys = map(lambda key: my_dict[key]**2, my_dict)
# Convert the map object to a list to see the results
result = list(squared_keys)
# Print the squared keys
print(result)
Replit 강의 자료가 안나와요
0
18
1
Replit UI 변경으로 인한 실습 진행 문의
1
27
1
replit에서 developer frameworks가 안보여요
0
88
2
[업데이트] 파이썬 패키지 부분에서 안되어서 강의 진행 불가
2
112
3
html 읽기 오류
1
111
2
DataFrame groupby 사용관련 질문
1
120
2
pylint shell 사용법
0
85
2
자막오류 수정가능한가요?
0
94
1
복합 조건절 관련 궁금증
0
88
2
49.행맨 프로그램 - 재시도 횟수 관련.
1
87
1
64. 파이썬 입문자가 쉽게 빠지기 쉬운 몇가지 에러(혹은 로직)에 대해 알아보기
0
118
2
Replit UI가 업데이트 되서 강의 진행이 멈췄어요
2
201
3
Replit을 사용해보려고 하는데 영상처럼 진행이 안되네요
3
491
2
실무에서의 제네레이터 함수 사용에 관한 질문입니다.
0
74
2
영상이 소리만 나오고 영상은 안보입니다.
0
99
2
pandas 오류 질문
0
146
2
상속 질문
1
138
2
total을 float으로 바꾸신 이유
0
208
2
섹션2 ["환경 vs. 설정 vs. 구성"] 강의 자막 문의
0
148
1
파이썬 data insert to table
0
243
2
파이썬 Class Method 질문
0
168
2
timeit 쓸 때는 만들었던 함수를 재사용 할 수는 없는지?
0
139
2
__repr__ 와 __str__ 차이점?
0
211
2
class method vs static method
0
293
2





