Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to sort the list while keeping the original order of equal elements.
DSA Python
sorted_list = sorted(data, key=lambda x: x.age, [1]=True)
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-existent parameter like 'stable' or 'stable_sort'.
Confusing 'reverse' with sorting stability.
✗ Incorrect
The 'reverse' parameter controls sorting order. Stability is guaranteed by Python's sorted by default.
2fill in blank
mediumComplete the code to perform a stable sort by the 'score' attribute.
DSA Python
data.sort(key=lambda x: x.score, [1]=False)
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to use a 'stable' parameter which does not exist.
Setting 'reverse' to True when ascending order is needed.
✗ Incorrect
The 'reverse' parameter controls sorting order; Python's sort is stable by default.
3fill in blank
hardFix the error in the code to ensure a stable sort by 'name'.
DSA Python
sorted_data = sorted(data, key=lambda x: x.name, [1]=False)
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'stable' which is not a valid parameter.
Confusing sorting order with stability.
✗ Incorrect
The 'reverse' parameter controls sorting order; stability is guaranteed by default.
4fill in blank
hardFill both blanks to create a dictionary of word lengths for words longer than 3 characters.
DSA Python
{word: [1] for word in words if len(word) [2] 3}Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself as the value instead of its length.
Using '<' instead of '>' in the condition.
✗ Incorrect
We want the length of each word (len(word)) and only words longer than 3 (>) are included.
5fill in blank
hardFill all three blanks to create a dictionary with uppercase keys and values greater than 0.
DSA Python
result = { [1]: [2] for k, v in data.items() if v [3] 0 }Attempts:
3 left
💡 Hint
Common Mistakes
Using original keys instead of uppercase keys.
Using '<' instead of '>' in the condition.
Using k instead of v for values.
✗ Incorrect
Keys are uppercase (k.upper()), values are v, and filter keeps values greater than 0 (>).
