zip , enumurate
1 2 3 4 5 6 | alist = ['a1', 'a2', 'a3'] blist = ['b1', 'b2', 'b3'] for a, b in zip(alist, blist): print(a, b) | cs |
1 2 3 4 5 | a, b, c = zip((1, 2, 3), (10, 20, 30), (100, 200, 300)) print(a, b, c) print([sum(x) for x in zip((1, 2, 3), (10, 20, 30), (100, 200, 300))]) | cs |
1 2 3 4 5 6 | alist = ['a1', 'a2', 'a3'] blist = ['b1', 'b2', 'b3'] for i, (a, b) in enumerate(zip(alist, blist)): print(i, a, b) | cs |
1 | list(map(lambda x: x**2 if x % 2==0 else x, ex)) | cs |
1 2 3 4 5 6 7 8 9 10 | # Reduce from functools import reduce print(reduce(lambda x, y: x+y, [1,2,3,4,5])) def factorial(n): return reduce(lambda x, y: x * y, range(1, n+1)) print(factorial(5)) | cs |
-python for machine learning in edwith
'* Computer Science > py' 카테고리의 다른 글
bulk printer with py (0) | 2018.12.07 |
---|---|
git bash에서 파이썬으로 git untracked files 제거 (0) | 2018.08.15 |
collections (0) | 2018.07.09 |
Asterisk (0) | 2018.07.09 |
join & traslate & title (0) | 2018.03.04 |