0
0
Data Analysis Pythondata~10 mins

Memory-efficient operations in Data Analysis 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 create a generator expression that saves memory.

Data Analysis Python
squares = (x[1]2 for x in range(1, 6))
print(list(squares))
Drag options to blanks, or click blank then click option'
A**
B*
C+
D//
Attempts:
3 left
💡 Hint
Common Mistakes
Using multiplication (*) instead of exponentiation (**).
Using integer division (//) which is incorrect here.
2fill in blank
medium

Complete the code to convert a list to a generator expression for memory efficiency.

Data Analysis Python
numbers = [1, 2, 3, 4, 5]
generator = (num for num [1] numbers)
print(list(generator))
Drag options to blanks, or click blank then click option'
Aof
Bat
Cfrom
Din
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'of' or 'from' which are not valid in this context.
Using 'at' which is not a Python keyword for iteration.
3fill in blank
hard

Fix the error in the code to create a memory-efficient data filter using a generator.

Data Analysis Python
data = [10, 15, 20, 25, 30]
filtered = (x for x in data if x [1] 20)
print(list(filtered))
Drag options to blanks, or click blank then click option'
A!=
B>
C==
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<=' which keeps numbers less or equal to 20.
Using '==' which keeps only numbers equal to 20.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that stores word lengths only for words longer than 3 letters.

Data Analysis Python
words = ['cat', 'house', 'dog', 'elephant']
lengths = {word: [1] for word in words if len(word) [2] 3}
print(lengths)
Drag options to blanks, or click blank then click option'
Alen(word)
Bword
C>
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself as the value instead of its length.
Using '<=' which filters words shorter or equal to 3 letters.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that stores uppercase words as keys and their lengths as values, only for words longer than 4 letters.

Data Analysis Python
words = ['apple', 'bat', 'carrot', 'dog']
result = { [1]: [2] for w in words if len(w) [3] 4 }
print(result)
Drag options to blanks, or click blank then click option'
Aw.upper()
Blen(w)
C>
Dw
Attempts:
3 left
💡 Hint
Common Mistakes
Using the original word as key instead of uppercase.
Using '<=' which filters shorter or equal length words.