1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| def func(x): return x * x for i in map(func, [1, 2, 3]): print(i)
for i in map(lambda x: x*x, [1, 2, 3]): print(i) for i in map(lambda x,y: x+y, [1,3,5], [2,4,6]): print(i)
for i in filter(lambda e: e%2, [1, 2, 3]): print(i)
print(sorted([1, 5, 2], reverse=True))
print(sorted([('b', 2), ('a', 1)], key=lambda x:x[0]))
l1 = ['a','b','c'] l2 = [1,2,3] for i in zip(l1, l2): print(i)
for i in zip(*zip(l1, l2)): print(i)
from functools import reduce def add(x, y): return x + y print(reduce(add, [1, 3, 5]))
eval("1+2*3")
r = compile("3*4+5",'','eval') eval(r)
r = compile("print('hello,world')", "<string>", "exec") exec(r)
|