Dec-04-2019, 02:26 AM
(Dec-03-2019, 11:12 PM)mrsenorchuck Wrote: So currently my premier dictionalry has two keys and it has to have two to make the key value unique.
These keys are Team and Year.
Would my best option be to create a new dictionary based on my existing dictionary for a named team?
For example a team like Leeds United dosen't have a year value for 2008 etc
It sounds like you need multiple dimensions to your dictionary.
A dictionary is a singular key: value relationship, so you can only use one key in a dictionary.
For instance:
grades = {"Mike": 99, "Sally": 100, "Thomas": 82}In this dictionary the students' names are the keys and their grades are the values.
So:
print(grades["Mike"])Gives us:
Output:99
If we wanted to store multiple grades per student we could make a dictionary of dictionaries, as such:grades = {"Mike": {"Test": 100, "Quiz": 98, "Homework": 99}, "Sally": {"Test": 100, "Quiz": 100, "Homework": 100}, "Thomas": {"Test": 85, "Quiz": 82, "Homework": 79} }Then we could access any given grade by first the name of the student, then the type of grade, as such:
print(grades["Mike"]["Quiz"])Which gives us:
Output:98
For each type of key that you'd like to use, you will need to nest another dictionary. In you case the inner dictionaries should all be the same as shown in this example. I believe you will need three levels of dictionaries.Try to put some code together based on this. You are more likely to get help on code that you've made and tested, especially if you post all the code using the formatting tools and your results or tracebacks in the case of errors.