Merge Without Duplicates
Python
25 pts
Merge Without Duplicates
A bus visits some towns in the morning and some in the evening. Some towns appear in both lists. Build all_stops:
- Start with a real copy of
morning. - Loop through
eveningandappend()each town only if it is not already inall_stops.
morning and evening must not change. Print all_stops and its length. Expected output:
['Asmara', 'Keren', 'Massawa', 'Assab', 'Nakfa'] 5
Checklist
- Keep
morningandeveningunchanged. - Create
all_stopsas a real copy ofmorning. - Loop through
eveningand add each town only if it is not already inall_stops. - Print
all_stopsand then its length.
🔑 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.
