0
0
Pythonprogramming~10 mins

Lambda with map() in Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to double each number in the list using map and a lambda function.

Python
numbers = [1, 2, 3, 4]
doubled = list(map(lambda x: x [1] 2, numbers))
print(doubled)
Drag options to blanks, or click blank then click option'
A*
B+
C-
D/
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using + instead of * will add 2 instead of doubling.
Using / will divide the number by 2, not double it.
2fill in blank
medium

Complete the code to convert each string in the list to uppercase using map and a lambda.

Python
words = ['apple', 'banana', 'cherry']
upper_words = list(map(lambda w: w[1](), words))
print(upper_words)
Drag options to blanks, or click blank then click option'
Alower
Bcapitalize
Cupper
Dtitle
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using lower() will convert to lowercase instead.
Using capitalize() only changes the first letter.
3fill in blank
hard

Fix the error in the lambda function to add 5 to each number using map.

Python
nums = [10, 20, 30]
result = list(map(lambda n: n [1] 5, nums))
print(result)
Drag options to blanks, or click blank then click option'
A-
B*
C/
D+
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using - subtracts 5 instead of adding.
Using * multiplies instead of adding.
4fill in blank
hard

Fill both blanks to create a list of squares of even numbers only using map and filter with lambda.

Python
numbers = [1, 2, 3, 4, 5, 6]
even_squares = list(map(lambda x: x[1]2, filter(lambda x: x [2] 2 == 0, numbers)))
print(even_squares)
Drag options to blanks, or click blank then click option'
A**
B%
C//
D+
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using + or // instead of ** for squaring.
Using // or + instead of % for checking evenness.
5fill in blank
hard

Fill all three blanks to create a dictionary with uppercase keys and values doubled only if value is greater than 10.

Python
data = {'a': 5, 'b': 15, 'c': 20}
result = { [1]: [2]*2 for k, v in data.items() if v [3] 10 }
print(result)
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
C>
Dk
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using k instead of k.upper() for keys.
Using v without doubling.
Using < or == instead of > in the condition.