0
0
Pythonprogramming~10 mins

Sorting and reversing lists 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 sort the list in ascending order.

Python
numbers = [5, 3, 8, 1]
numbers.[1]()
print(numbers)
Drag options to blanks, or click blank then click option'
Apop
Breverse
Cappend
Dsort
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using reverse() instead of sort(), which only flips the list order.
Using append() or pop(), which add or remove items instead of sorting.
2fill in blank
medium

Complete the code to reverse the order of the list.

Python
letters = ['a', 'b', 'c', 'd']
letters.[1]()
print(letters)
Drag options to blanks, or click blank then click option'
Areverse
Bpop
Csort
Dinsert
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using sort() which arranges items but does not reverse the current order.
Using pop() or insert() which modify list items but do not reverse.
3fill in blank
hard

Fix the error in the code to sort the list in descending order.

Python
scores = [70, 85, 90, 60]
scores.sort([1]=True)
print(scores)
Drag options to blanks, or click blank then click option'
Areverse=True
Bdescending
Creverse
Dreverse_order
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using incorrect argument names like 'descending' or 'reverse_order'.
Putting the whole argument 'reverse=True' as the blank instead of just the argument name.
4fill in blank
hard

Fill both blanks to create a dictionary with words as keys and their lengths as values, only for words longer than 3 letters.

Python
words = ['cat', 'house', 'tree', 'a', 'dog']
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)
B<=
C>
Dword
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using the wrong comparison operator like '<=' which selects shorter words.
Using 'word' instead of 'len(word)' for the dictionary values.
5fill in blank
hard

Fill all three blanks to create a dictionary with uppercase words as keys and their lengths as values, only for words longer than 2 letters.

Python
words = ['hi', 'hello', 'yes', 'no']
result = { [1]: [2] for w in words if len(w) [3] 2 }
print(result)
Drag options to blanks, or click blank then click option'
Aw.upper()
Blen(w)
C>
Dw.lower()
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using lowercase words as keys instead of uppercase.
Using wrong comparison operator like '<='.
Using the word itself as value instead of its length.