Question

Assuming x and y each are a list of integers, answer the following questions. Use a...

Assuming x and y each are a list of integers, answer the following questions. Use a as a running variable. If necessary use b as an additional running variable. Do not use any other variables as you do not need.

a. Write a Python statement using lambda calculus map to map x to y where every element of y is incremented by 1.

b. Write a Python statement using lambda calculus reduce to reduce x to s, where s is the sum of x. Do not use sum function.

c. Write a Python statement using lambda calculus filter to filter out odd integers from x such that y has only even integers.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
SOURCE CODE:

*Please follow the comments to better understand the code.

**Please look at the Screenshot below and use this code to copy-paste.

***The code in the below screenshot is neatly indented for better understanding.



This is a big question.
I have solved all of them. 
Please give me an upvote dear, Much Appreciated.!!


from functools import reduce

# (a) Write a Python statement using lambda calculus map
#     to map x to y where every element of y is incremented by 1.

y = [10, 20, 30, 40, 50]
# Now, use a map function and lambda to increment each value of y by 1
x = map(lambda a: a + 1, y)
# Print the result
print("Result of map is", list(x))

#  (b) Write a Python statement using lambda calculus reduce
#      to reduce x to s, where s is the sum of x.
x = [1, 2, 3, 4, 5]
# Use reduce and lambda here
s = reduce(lambda a, b: a + b, x)
# Print the result
print("Sum of values in", x, "is", s)

# (c) Write a Python statement using lambda calculus filter
#     to filter out odd integers from x such that y has only even integers.
x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
# Use filter and lambda here
y = filter(lambda a: a % 2 == 0, x)
# Print the result
print("Result of filter is", list(y))

If there are any doubts, comment down here. We are right here to help you. Happy Learning..!! PLEASE give an UPVOTE I Have Pu

Add a comment
Know the answer?
Add Answer to:
Assuming x and y each are a list of integers, answer the following questions. Use a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT