-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAssignment-4.py
79 lines (49 loc) · 1023 Bytes
/
Assignment-4.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
#!/usr/bin/env python
# coding: utf-8
# Write a Python program to create a lambda function that adds 25 to a given number passed in as an argument.
#
#
#
# sample input: 10
#
# sample output: 35
# In[15]:
r = lambda a : a + 25
print(r(10))
# Write a Python program to triple all numbers of a given list of integers. Use Python map.
#
#
#
# sample list: [1, 2, 3, 4, 5, 6, 7]
#
#
#
# Triple of list numbers:
#
# [3, 6, 9, 12, 15, 18, 21]
# In[16]:
nums = (1,2,3,4,5,6,7)
print("original list: ", nums)
result = map(lambda x: x + x + x, nums)
print("\nTriple of list numbers:")
print(list(result))
# In[ ]:
# Write a Python program to square the elements of a list using map() function.
#
#
#
# Sample List: [4, 5, 2, 9]
#
# Square the elements of the list:
#
# [16, 25, 4, 81]
# In[17]:
def square_num(n):
return n * n
nums = [4,5,2,9]
print("sample List: ",nums)
result = map(square_num, nums)
print("Square of the elements of list:")
print(list(result))
# In[ ]:
# In[ ]: