MAP
- 여러개의 데이터(리스트, 딕셔너리, 세트) 요소를 지정된 함수/lambda 로 처리해주는 함수 - iterable의 각 원소마다 함수를 적용 - map(self, /, *args, ** kwargs) 가변포지션 map #shift + tab : map(func, *iterables) --> map object ==> map def x(a): return a+1 map(x, [1,2,3,4]) #결과 안나옴 ==> list(map(x, [1,2,3,4])) #list 이용 결과 볼수 있음 ==> [2, 3, 4, 5] t = map(lambda x:x+10, [1,2,3]) t ==> list(t) ==> [11, 12, 13]
더보기
iterable
1. iterable - for 문에 사용 가능 - 동시에 여러개 값을 처리한는거같지만 내부적으로 1씩 뽑아서 처리 - iterable : iterator 이 되 수 있음 - 대부분의 컨테이너는 iterable :list, dictionary, tuple.. #a의 값은 1개, 원소 3개 a= [1,2,3,] #여러 값을 한번에 할당 #list는 iterable dir(a) # _iter__ -> iterable -> iterator 될 수 있음 list('abc') # instance 문자열을 쪼갬 ==> ['a', 'b', 'c'] ['a', 'b', 'c'] #lietral ==> ['a', 'b', 'c'] 2. iterable 종류 (1) set a= {1,2,3} b= iter(a) b ==>..
더보기