Challenge - 5 Problems
Memory Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of memory-efficient data filtering
What is the output of this code that filters a large list using a generator expression?
Data Analysis Python
data = range(1_000_000) filtered = (x for x in data if x % 100_000 == 0) result = list(filtered) print(result)
Attempts:
2 left
💡 Hint
Remember that range stops before the stop value and 0 is included in range(1_000_000).
✗ Incorrect
The range goes from 0 to 999,999. Numbers divisible by 100,000 in this range include 0 up to 900,000. 1,000,000 is not included.
❓ data_output
intermediate2:00remaining
Memory usage difference between list and generator
Which option correctly describes the memory usage difference when creating a list vs a generator for numbers 0 to 999,999?
Data Analysis Python
import sys list_data = list(range(1_000_000)) gen_data = (x for x in range(1_000_000)) print(sys.getsizeof(list_data)) print(sys.getsizeof(gen_data))
Attempts:
2 left
💡 Hint
Think about when values are stored in memory for lists vs generators.
✗ Incorrect
Lists store all elements in memory, while generators produce items one by one, using much less memory.
🔧 Debug
advanced2:00remaining
Identify the error in memory-efficient data processing
What error will this code raise when trying to sum a large dataset using a generator?
Data Analysis Python
data = (int(x) for x in ['1', '2', 'three', '4']) total = sum(data) print(total)
Attempts:
2 left
💡 Hint
Check the conversion of strings to integers.
✗ Incorrect
The string 'three' cannot be converted to int, causing a ValueError during iteration.
🚀 Application
advanced2:00remaining
Choosing memory-efficient data aggregation method
You have a huge CSV file with millions of rows. Which method is most memory-efficient to calculate the average of a numeric column without loading all data at once?
Attempts:
2 left
💡 Hint
Think about how to avoid loading all data into memory.
✗ Incorrect
Reading line by line and aggregating avoids loading the entire dataset, saving memory.
🧠 Conceptual
expert2:00remaining
Understanding memory-efficient streaming with pandas
Which pandas function allows processing large CSV files in chunks to reduce memory usage?
Attempts:
2 left
💡 Hint
Look for a parameter that reads the file in parts.
✗ Incorrect
The chunksize parameter reads the file in smaller parts (chunks), allowing memory-efficient processing.