Learn practical skills, build real-world projects, and advance your career
Created 5 years ago
Write a Python Program to implement your own myreduce() function which works exactly like Python's built-in function reduce()
product=1
x=[1,2,3,4]
def myreduce(product):
for i in x:
product *= i
return product
print(myreduce(product))
24
Write a Python program to implement your own myfilter() function which works exactly like Python's built-in function filter()
result = []
def myfilter(result):
for x in range(-10,10):
if x > 0:
result.append(x)
return result
print(myfilter(result))
[1, 2, 3, 4, 5, 6, 7, 8, 9]
'''Implement List comprehensions to produce the following lists.
Write List comprehensions to produce the following Lists
['A', 'C', 'A', 'D', 'G', 'I', ’L’, ‘ D’]
['x', 'xx', 'xxx', 'xxxx', 'y', 'yy', 'yyy', 'yyyy', 'z', 'zz', 'zzz', 'zzzz']
['x', 'y', 'z', 'xx', 'yy', 'zz', 'xx', 'yy', 'zz', 'xxxx', 'yyyy', 'zzzz']
[[2], [3], [4], [3], [4], [5], [4], [5], [6]]
[[2, 3, 4, 5], [3, 4, 5, 6], [4, 5, 6, 7], [5, 6, 7, 8]]
[(1, 1), (2, 1), (3, 1), (1, 2), (2, 2), (3, 2), (1, 3), (2, 3), (3, 3)]'''