python-mastery/Exercises/soln2_2.md
2023-07-16 20:21:00 -05:00

851 B
Raw Blame History

Exercise 2.2 - Solution

There is no official solution for this exerciseyou 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 arent 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 from collections 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.

Back