Backup and Compare
Python
25 pts
Backup and Compare
A delivery company keeps a set of the cities it serves.
- Make an independent copy of
citiescalledbackup(usecopy()). - Change
cities: discard"Keren"and add"Nakfa". - Create
changed— the cities that are in exactly one ofcitiesandbackup(usesymmetric_difference()). - Print
sorted(cities),sorted(backup)andsorted(changed).
Expected output:
['Asmara', 'Massawa', 'Nakfa'] ['Asmara', 'Keren', 'Massawa'] ['Keren', 'Nakfa']
Checklist
- Make an independent copy of
citiescalledbackup, before you change anything. - Discard
"Keren"fromcitiesand add"Nakfa". - Create
changedwithsymmetric_difference(). - Print
cities,backupandchanged, each sorted.
🔑 Solution
If you view the solution before passing, you earn half points for this exercise. You still need to type it and press Check to finish.
How it works, step by step
Point at a step to highlight its lines. Type the solution yourself and press Check answer to finish.
