Harold Nelson
2/10/2020
Create a dictionary to record the weights of Joe (175), Tom (190), and Dick (150). Print the dictionary.
## {'Dick': 150, 'Joe': 175, 'Tom': 190}
Add Harry, who weighs 180 pounds to the dictionary and print the new dictionary.
Remove Joe from the dictionary and print the new dictionary.
Use the dict to look up Dick’s weight and print it.
Iterate over the items in the dictionary and calculate the sum of the weights. Print the sum.
Use the method items() to get the items in adict. Print the rti, the object returned by the items() method. What is the type of this object?
## dict_items([('Dick', 150), ('harry', 180.0), ('Tom', 190)])
## <class 'dict_items'>
Can you iterate over rti?
## ('Dick', 150)
## <class 'tuple'>
## ('harry', 180.0)
## <class 'tuple'>
## ('Tom', 190)
## <class 'tuple'>
Can you use an integer index to obtain one of the things in rti?
Can you convert rti to a list using the list() function? Can you retrieve items from this list with a numerical index?
## [('Dick', 150), ('harry', 180.0), ('Tom', 190)]
## <class 'list'>
## ('Dick', 150)
Use the method keys() to extract something called my_keys from the dictionary. What is it? What is it’s type? Can you iterate over it? Can you use a numerical index? Can you convert it to a list?
## dict_keys(['Dick', 'harry', 'Tom'])
## <class 'dict_keys'>
## Dick <class 'str'>
## harry <class 'str'>
## Tom <class 'str'>
## <class 'list'>
Use the method values() to extract something called my_keys from the dictionary. What is it? What is it’s type? Can you iterate over it? Can you use a numerical index? Can you convert it to a list?
## dict_values([150, 180.0, 190])
## <class 'dict_values'>
## 150 <class 'int'>
## 180.0 <class 'float'>
## 190 <class 'int'>
## <class 'list'>