Question

Use Python. Let a be the list of values produced by range(1, 11). a). Using the...

Use Python.

Let a be the list of values produced by range(1, 11).

a). Using the function map with a lambda argument, write an expression that will produce
each of the following:

i) A list of cubic of the corresponding values in the original list; The expected output
should be a list as follows,

[1, 8, 27, 64, 125, 216, 343, 512, 729, 1000]

ii) A list where each element is larger by one than the corresponding element in the
original list; The expected output should be a list as follows,

[2, 3, 4, 5, 6, 7, 8, 9, 10, 11]

b) Write a list comprehension that will produce each of the following:

i)  A list contains values in the original list that are less than or equal to 5; The
expected output should be a list as follows,

[1, 2, 3, 4, 5]

ii) A list contains values that are the square of odd values in the original list. The
expected output should be a list as follows,

[1, 9, 25, 49, 81]

0 0
Add a comment Improve this question Transcribed image text
Answer #1
# Let a be the list of values produced by range(1, 11).
a = list(range(1, 11))
# a). Using the function map with a lambda argument, write an expression that will produce
# each of the following:
#
# i) A list of cubic of the corresponding values in the original list; The expected output
# should be a list as follows,
print(list(map(lambda x: x ** 3, a)))
# [1, 8, 27, 64, 125, 216, 343, 512, 729, 1000]
#
# ii) A list where each element is larger by one than the corresponding element in the
# original list; The expected output should be a list as follows,
print(list(map(lambda x: x + 1, a)))
# [2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
#
# b) Write a list comprehension that will produce each of the following:
#
# i)  A list contains values in the original list that are less than or equal to 5; The
# expected output should be a list as follows,
print([x for x in a if x <= 5])
# [1, 2, 3, 4, 5]
#
# ii) A list contains values that are the square of odd values in the original list. The
# expected output should be a list as follows,
print([x * x for x in a if x % 2 == 1])
# [1, 9, 25, 49, 81]

Add a comment
Know the answer?
Add Answer to:
Use Python. Let a be the list of values produced by range(1, 11). a). Using the...
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