1. An empty dictionary without any items is written with just two curly braces, like this: {}. mydictionary={}
2. The following shows the creation of a simple dictionary. What is the output when run?
#creating a dictionary of key value pairs that stores the names of the upcoming iphones and their release date
#NOT SORTED - note they are not necessarily printed/displayed in the order you create them!
future_release = {
"iphone10" : 2017,
"iphone 11" : 2018,
"iphone 12" : 2019,
"iphone 13" : 2020,
"iphone 14" : 2021,
"iphone 15" : 2022
}
print(future_release.keys())
A list of all the phones and the years together.
A list of all the keys (e.g. 01, 02, 03, etc)
A list of all the years (e.g. 2017, 2018 etc)
A list of the phone versions (e.g. Iphone10, Iphone11 etc)
3. In this Python code that has created a specific dictionary, what is happening on line 7?
4. In the following code the keys are:
5. For the following code, what would the output be?
6. What is the output of the following code?
7. In Python: Suppose d = {“john”:40, “peter”:45}, to delete the entry for “john” what command do we use
a) d.delete(“john”:40)
8. Suppose d = {“john”:40, “peter”:45}. To obtain the number of entries in dictionary which command do we use?
9. Suppose d = {“john”:40, “peter”:45}, on trying to retrieve a value using the expression d[“susan”], there is a keyError exception.
10. What is the output of the following code that is making use of the dictionary structure?
11. In the following example, what is the output?
12. What is the result of this code?
>>> a={'B':5,'A':9,'C':7}
>>> sorted(a)
[‘B’,’C’,’A’].
[9,5,7].
[5,7,9].
[‘A’,’B’,’C’].
13. What is the result of the following code snippet?
>>> a={i: i*i for i in range(6)}
>>> a (note: dictionary comprehension is used in this example)
{0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6:36}
{0: 0, 1: 1, 4: 4, 9: 9, 16: 16, 25: 25}
None of these answers are valid
{0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25}
14. Function all() returns True if all keys of the dictionary are true or if the dictionary is empty.
15. This code snippet has the result of inverting the key-value pairs in the dictionary