Chapters
Python114 chapters

Exercises

Sets

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

Exercise 1

Print how many unique names there are.

Python
names = ["Ada", "Grace", "Ada", "Katherine"]
# print the number of unique names
Exercise 2

Remove duplicates but keep the first-seen order.

Python
names = ["Ada", "Grace", "Ada", "Katherine"]
# print them unique and in order
Exercise 3

Print who joined and who left between the two sets, sorted.

Python
before = {"ada", "grace"}
after = {"grace", "katherine"}
# print the joiners, then the leavers