-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction_eg.py
More file actions
53 lines (38 loc) · 825 Bytes
/
Copy pathfunction_eg.py
File metadata and controls
53 lines (38 loc) · 825 Bytes
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
46
47
48
49
__author__ = 'admin'
def mysum(L):
if not L:
return 0
else:
return L[0] + mysum(L[1:])
L = [1, 2 ,3 ,4 ,5]
print mysum(L)
def mysum(L):
return 0 if not L else L[0] + mysum(L[1:])
L = [1, 2 ,3 ,4 ,5]
print mysum(L)
f = lambda x,y,z: x + y +z
print f(2,4,5)
x = (lambda a ='fee', b='fie', c='feo':a+b+c)
print x('wee')
print x(a='bb',b='cc',c='dd')
L = [lambda x:x ** 2,
lambda x:x ** 3,
lambda x:x ** 4]
for f in L:
print(f(2))
key = 'got'
map_fun = {
'already':(lambda: 2 + 2),
'got': (lambda : 2 *4 ),
'one':(lambda:2 ** 6),
'param':(lambda x: x**2)
}
print map_fun['got']()
print map_fun['one']()
print map_fun['param'](2)
s1 = 'abc'
s2 = 'xyz'
print list(zip(s1, s2))
print dict(zip(s1,s2))
print [x + y for x in [1 ,2 , 3] for y in [5, 6 ,7]]
print {x:y for x in [1,2,3] for y in [5,6,7]}