-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLabMainFile.py
More file actions
48 lines (38 loc) · 1.1 KB
/
LabMainFile.py
File metadata and controls
48 lines (38 loc) · 1.1 KB
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
import datetime
from functools import reduce
x = 10 # global var
def main():
#x = 1 #local var
global x
print("hello")
#print(x)
#print(findMyAge())
#-------findMyAge()
#print(map(lambda w: len(w), 'It is raining cats and dogs'.split()))
#map(<function>, <sequence/list>)
#TODO: map() & lambda
#---------lamdatest()
test()
def findMyAge():
print(datetime.date.today())
dob = input("Enter your year of birth : ")
currdate = datetime.datetime.now().year #datetime.date.today()
age = currdate - int(dob)
print(age)
#return age
def lamdatest():
sentence = 'It is raining cats and dogs'
words = sentence.split()
print(words)
lengths = map(lambda word: len(word), words)
print(lengths)
def test():
items = [1, 2, 3, 4, 5]
squared = list(map(lambda x: x ** 2, items))
print(squared)
print(list(map(lambda x:x+1,[1,2])))
print("\nreduce ::: ")
print(reduce(lambda x, y: x + y, [1, 2, 3, 4]))
print("\nmap ::: ")
print(list(map(lambda x,y:x+y, [1,2,3,4,],[2,3,4,2])))
if __name__ == '__main__':main()