<reponame>skunkworksdev/Python_Programming_Michigan
# 11.2. Getting Started with Dictionaries

"""
To provide an example of this new kind of datatype, we will create a dictionary
to translate English words into Spanish. For this dictionary, the keys are
strings and the values will also be strings.

One way to create a dictionary is to start with the empty dictionary and add
key-value pairs. The empty dictionary is denoted {}.
"""

eng2sp = {}
eng2sp['one'] = 'uno'
eng2sp['two'] = 'dos'
eng2sp['three'] = 'tres'
print(eng2sp)

"""
The first assignment creates an empty dictionary named eng2sp. The other 
assignments add new key-value pairs to the dictionary. The left hand side 
gives the dictionary and the key being associated. The right hand side 
gives the value being associated with that key. We can print the current 
value of the dictionary in the usual way. The key-value pairs of the 
dictionary are separated by commas. Each pair contains a key and a value 
separated by a colon.

The order of the pairs may not be what you expected. Python uses complex 
algorithms, designed for very fast access, to determine where the key-value 
pairs are stored in a dictionary. For our purposes we can think of this 
ordering as unpredictable.

Another way to create a dictionary is to provide a bunch of key-value pairs 
using the same syntax as the previous output.
"""

eng2sp = {'three': 'tres', 'two': 'dos', 'one': 'uno'}
print(eng2sp)

"""
It doesn’t matter what order we write the pairs. The values in a dictionary 
are accessed with keys, not with indices, so there is no need to care about 
ordering.

Here is how we use a key to look up the corresponding value.
"""
eng2sp = {'three': 'tres', 'two': 'dos', 'one': 'uno'}
value = eng2sp['two']
print(value)
print(eng2sp['one'])

# The key 'two' yields the value 'dos'. The key one yields the value uno.
#
# Check your understanding
"""
dictionaries-1-1: A dictionary is an unordered collection of key-value pairs.
[x] True
[ ] False
"""

# dictionaries-1-2: What is printed by the following statements?
mydict = {'cat': 12, 'dog': 6, 'elephant': 23}
print(mydict['dog'])

"""
3. Create a dictionary that keeps track of the USA’s Olympic medal count. Each 
key of the dictionary should be the type of medal (gold, silver, or bronze) 
and each key’s value should be the number of that type of medal the USA’s won. 
Currently, the USA has 33 gold medals, 17 silver, and 12 bronze. Create a 
dictionary saved in the variable medals that reflects this information.
"""

medals = {'gold': 33, 'silver': 17, 'bronze': 12}
print(medals)

"""
4. You are keeping track of olympic medals for Italy in the 2016 Rio Summer 
Olympics! At the moment, Italy has 7 gold medals, 8 silver metals, and 6 bronze 
medals. Create a dictionary called olympics where the keys are the types of 
medals, and the values are the number of that type of medals that Italy has 
won so far.
"""

olympics = {}
olympics['gold'] = 7
olympics['silver'] = 8
olympics['bronze'] = 6
print(olympics)

# 11.2. Getting Started with Dictionaries

"""
To provide an example of this new kind of datatype, we will create a dictionary
to translate English words into Spanish. For this dictionary, the keys are
strings and the values will also be strings.

One way to create a dictionary is to start with the empty dictionary and add
key-value pairs. The empty dictionary is denoted {}.
"""

eng2sp = {}
eng2sp['one'] = 'uno'
eng2sp['two'] = 'dos'
eng2sp['three'] = 'tres'
print(eng2sp)

"""
The first assignment creates an empty dictionary named eng2sp. The other 
assignments add new key-value pairs to the dictionary. The left hand side 
gives the dictionary and the key being associated. The right hand side 
gives the value being associated with that key. We can print the current 
value of the dictionary in the usual way. The key-value pairs of the 
dictionary are separated by commas. Each pair contains a key and a value 
separated by a colon.

The order of the pairs may not be what you expected. Python uses complex 
algorithms, designed for very fast access, to determine where the key-value 
pairs are stored in a dictionary. For our purposes we can think of this 
ordering as unpredictable.

Another way to create a dictionary is to provide a bunch of key-value pairs 
using the same syntax as the previous output.
"""

eng2sp = {'three': 'tres', 'two': 'dos', 'one': 'uno'}
print(eng2sp)

"""
It doesn’t matter what order we write the pairs. The values in a dictionary 
are accessed with keys, not with indices, so there is no need to care about 
ordering.

Here is how we use a key to look up the corresponding value.
"""
eng2sp = {'three': 'tres', 'two': 'dos', 'one': 'uno'}
value = eng2sp['two']
print(value)
print(eng2sp['one'])

# The key 'two' yields the value 'dos'. The key one yields the value uno.
#
# Check your understanding
"""
dictionaries-1-1: A dictionary is an unordered collection of key-value pairs.
[x] True
[ ] False
"""

# dictionaries-1-2: What is printed by the following statements?
mydict = {'cat': 12, 'dog': 6, 'elephant': 23}
print(mydict['dog'])

"""
3. Create a dictionary that keeps track of the USA’s Olympic medal count. Each 
key of the dictionary should be the type of medal (gold, silver, or bronze) 
and each key’s value should be the number of that type of medal the USA’s won. 
Currently, the USA has 33 gold medals, 17 silver, and 12 bronze. Create a 
dictionary saved in the variable medals that reflects this information.
"""

medals = {'gold': 33, 'silver': 17, 'bronze': 12}
print(medals)

"""
4. You are keeping track of olympic medals for Italy in the 2016 Rio Summer 
Olympics! At the moment, Italy has 7 gold medals, 8 silver metals, and 6 bronze 
medals. Create a dictionary called olympics where the keys are the types of 
medals, and the values are the number of that type of medals that Italy has 
won so far.
"""

olympics = {}
olympics['gold'] = 7
olympics['silver'] = 8
olympics['bronze'] = 6
print(olympics)
# 11.2. Getting Started with Dictionaries To provide an example of this new kind of datatype, we will create a dictionary to translate English words into Spanish. For this dictionary, the keys are strings and the values will also be strings.  One way to create a dictionary is to start with the empty dictionary and add key-value pairs. The empty dictionary is denoted {}. The first assignment creates an empty dictionary named eng2sp. The other  assignments add new key-value pairs to the dictionary. The left hand side  gives the dictionary and the key being associated. The right hand side  gives the value being associated with that key. We can print the current  value of the dictionary in the usual way. The key-value pairs of the  dictionary are separated by commas. Each pair contains a key and a value  separated by a colon.  The order of the pairs may not be what you expected. Python uses complex  algorithms, designed for very fast access, to determine where the key-value  pairs are stored in a dictionary. For our purposes we can think of this  ordering as unpredictable.  Another way to create a dictionary is to provide a bunch of key-value pairs  using the same syntax as the previous output. It doesn’t matter what order we write the pairs. The values in a dictionary  are accessed with keys, not with indices, so there is no need to care about  ordering.  Here is how we use a key to look up the corresponding value. # The key 'two' yields the value 'dos'. The key one yields the value uno. # # Check your understanding dictionaries-1-1: A dictionary is an unordered collection of key-value pairs. [x] True [ ] False # dictionaries-1-2: What is printed by the following statements? 3. Create a dictionary that keeps track of the USA’s Olympic medal count. Each  key of the dictionary should be the type of medal (gold, silver, or bronze)  and each key’s value should be the number of that type of medal the USA’s won.  Currently, the USA has 33 gold medals, 17 silver, and 12 bronze. Create a  dictionary saved in the variable medals that reflects this information. 4. You are keeping track of olympic medals for Italy in the 2016 Rio Summer  Olympics! At the moment, Italy has 7 gold medals, 8 silver metals, and 6 bronze  medals. Create a dictionary called olympics where the keys are the types of  medals, and the values are the number of that type of medals that Italy has  won so far.