[Python] Map, Filter, Zip
1. map, filter 1) map list와 같은 iterable 객체의 모든 element에 함수를 적용한 후 return 한다 map(function, iterable, ...) >>> list1 = [1,2,3,4,5,6]>>> list (map( lambda x : x//2 if x > 3 else x%2 , list1))[1, 0, 1, 2, 2, 3] 다음은 여러개의 입력을 받아서 int형으로 변환하는 예제 a, b = map(int, input().strip().split(' '))print(str(a//b) , str(a%b)) 2) filter list와 같은 iterable 객체의 모든 element에 함수를 적용한 후 True에 해당하는 element를 포함한 iterable을 ..
2019. 3. 27.
[Python] collections
1. collections.Counter() >>> import collections # from collections import Counter>>> my_list = ['a','z','c','a','f','q','c']>>> result = collections.Counter(my_list)>>> result Counter({'a': 2, 'c': 2, 'z': 1, 'f': 1, 'q': 1}) >>> list(result) ['a', 'z', 'c', 'f', 'q'] >>> my_list2 = ['a','z','z']>>> result.update(my_list2)>>> resultCounter({'a': 3, 'z': 3, 'c': 2, 'f': 1, 'q': 1}) >>> list(resul..
2019. 3. 27.