-
Notifications
You must be signed in to change notification settings - Fork 0
/
Python Functions.py
102 lines (45 loc) · 861 Bytes
/
Python Functions.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env python
# coding: utf-8
# In[1]:
# Functions
# In[2]:
def hello():
print("Hello")
# In[3]:
hello()
# In[4]:
# Function with parameter
# In[5]:
def add10(x):
return x+10
# In[6]:
add10(10)
# In[7]:
def even_odd(x):
if x%2==0:
print(x, " is even")
else:
print(x, "is odd")
# In[8]:
even_odd(5)
# In[9]:
#Lambda functions
# In[10]:
g = lambda x: x*x*x
print(g(7))
# In[11]:
#Lambda functions with filter
li = [5,7,22,97,54,62,77,23,73,61]
final_list = list(filter(lambda x: (x%2 != 0), li))
print(final_list)
# In[12]:
#Lambda functions with map
li = [5,7,22,97,54,62,77,23,73,61]
final_list = list(map(lambda x: x*2, li))
print(final_list)
# In[13]:
from functools import reduce
li = [5,8,10,20,50,100]
sum = reduce((lambda x, y: x+y), li)
print(sum)
# In[ ]: