Python | Working with sets exercise | Use sets to remove duplicates and compare two lists
This exercise is provided to allow potential course delegates to choose the correct Wise Owl Microsoft training course, and may not be reproduced in whole or in part in any format without the prior written consent of Wise Owl.
You need a minimum screen resolution of about 700 pixels width to see our exercises. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.
Open the file in the above folder and update the file path to point to the above folder too:
You'll need to change this file path for this program to work.
Run the program - it should print out two lists of grand prix (one for 2016, and the other for 2017):
A part of the output from the program. Each list contains duplicates, and there are discrepancies between the two lists.
Create variables holding the two lists as sets instead (this will, miraculously, automatically remove any duplicates), and use the correct set operator to list out all the elements in one set but not in both:
You'll need to use an if condition to determine which list each element belonged to so that you can include the year in each message.
When you've finished, take a moment to reflect on just how few lines of code that took, then close your file down.