Chapters
Python114 chapters

Exercises

Dict and Set Comprehensions

3 tasks. Write the code, press Check, and the page runs it against a real Python interpreter.

Exercise 1

Build a dictionary mapping each word to its length.

Python
words = ["ada", "grace"]
# print {'ada': 3, 'grace': 5}
Exercise 2

Keep only the entries scoring above 5.

Python
scores = {"ada": 9, "grace": 4, "kat": 7}
# print only the high scores
Exercise 3

Print the unique lowercase words, sorted.

Python
words = ["Ada", "ada", "GRACE"]
# print ['ada', 'grace']