851 B
Exercise 2.2 - Solution
There is no official solution for this exercise–you need rely on your current Python knowledge. However, there are a few tips that can help.
For problems where you need to determine uniqueness, use a set. Sets aren’t allowed to have duplicates.
If you need to tabulate data, consider using a dictionary that maps keys to a numeric count. For example, to count rides on each bus route, you could make a dictionary that maps the route name to the total ride count for that route. A
Counter
object fromcollections
is perfect for this task.If you need to keep data in order or sort data, store it in a list.
You can make Python data structures out of almost anything. For example, dictionaries of sets, nested dictionaries, etc. You might need to do this to answer questions 3 and 4.