Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to return cached data if available.
Rest API
if cache.get('data') is not [1]: return cache.get('data')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using True or False instead of None to check cache presence.
✗ Incorrect
We check if the cached data is not None to use it and avoid extra server processing.
2fill in blank
mediumComplete the code to store response in cache after fetching.
Rest API
response = fetch_data() cache.[1]('data', response)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using get instead of set to store data.
✗ Incorrect
We use set to save the response in cache for future requests.
3fill in blank
hardFix the error in the code to check cache before fetching data.
Rest API
if cache.[1]('data'): return cache.get('data') else: data = fetch_data() cache.set('data', data) return data
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like has_key or contains.
✗ Incorrect
Use get to check if 'data' exists in cache; it returns None if not found.
4fill in blank
hardFill both blanks to create a cache dictionary comprehension filtering keys.
Rest API
filtered_cache = {k: v for k, v in cache.items() if k [1] 'user' and v [2] None} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using endswith instead of startswith.
Using 'is' instead of 'is not' for None check.
✗ Incorrect
We filter keys starting with 'user' and values that are not None.
5fill in blank
hardFill all three blanks to create a cache update with conditional filtering.
Rest API
cache_update = [1]: [2] for [3], val in new_data.items() if val > 0
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing variable names or using undefined names.
✗ Incorrect
We create a dictionary with keys k and values val from new_data filtering positive values.