DICTIONARY - REVISION 5
1. Which of the following statements create a dictionary?
a) d = {}
b) d = {“john”:40, “peter”:45}
c) d = {40:”john”, 45:”peter”}
d) All of the mentioned
2. Select the correct way to print Emma’s age.
student = {1: {'name': 'Emma', 'age': '27', 'sex': 'Female'},2: {'name': 'Mike', 'age': '22',
'sex': 'Male'}}
a) student[0][1]
b) student[1][“age”]
c) student[0][“age”]
3. Which of the following will delete key_value pair for key="tiger" in dictionary?
dic={"lion":"wild","tiger":"wild","cat":"domestic","dog":"domestic"}
a) del dic["tiger"]
b) dic["tiger"].delete()
c) delete(dic.["tiger"])
d) del(dic.["tiger"])
4. Which of the following are true of Python dictionaries:
a) A dictionary can contain any object type except another dictionary.
b) All the keys in a dictionary must be of the same type.
c) Items are accessed by their position in a dictionary.
d) Dictionaries can be nested to any depth.
e) Dictionaries are mutable.
f) Dictionaries are accessed by key.
5. Write a function that creates a dictionary where the key is the number from 1 to n and
values have the message "Odd" or "Even" next to each number.
Example : If n=5 then the dictionary is
D={1:"Odd",2:"Even",3:"Odd"……}
6. Write a function that takes a dictionary student as parameter where the key is the name
of the students and the value is his percentage. This functions transfer the contents of
Dictionary Student to Dictionary Toppers if their percentage is above 90
7. Write a function that takes a string as the parameter and creates a dictionary that keeps
the track of the alphabets present in the string along with its count.
Example if the string is OCCURRENCE then the dictionary must be
{"O":1,"C":3,"U":1,"R":2,"E":2,"N":1}
1. Which of the following statements create a dictionary?
a) d = {}
b) d = {“john”:40, “peter”:45}
c) d = {40:”john”, 45:”peter”}
d) All of the mentioned
2. Select the correct way to print Emma’s age.
student = {1: {'name': 'Emma', 'age': '27', 'sex': 'Female'},2: {'name': 'Mike', 'age': '22',
'sex': 'Male'}}
a) student[0][1]
b) student[1][“age”]
c) student[0][“age”]
3. Which of the following will delete key_value pair for key="tiger" in dictionary?
dic={"lion":"wild","tiger":"wild","cat":"domestic","dog":"domestic"}
a) del dic["tiger"]
b) dic["tiger"].delete()
c) delete(dic.["tiger"])
d) del(dic.["tiger"])
4. Which of the following are true of Python dictionaries:
a) A dictionary can contain any object type except another dictionary.
b) All the keys in a dictionary must be of the same type.
c) Items are accessed by their position in a dictionary.
d) Dictionaries can be nested to any depth.
e) Dictionaries are mutable.
f) Dictionaries are accessed by key.
5. Write a function that creates a dictionary where the key is the number from 1 to n and
values have the message "Odd" or "Even" next to each number.
Example : If n=5 then the dictionary is
D={1:"Odd",2:"Even",3:"Odd"……}
6. Write a function that takes a dictionary student as parameter where the key is the name
of the students and the value is his percentage. This functions transfer the contents of
Dictionary Student to Dictionary Toppers if their percentage is above 90
7. Write a function that takes a string as the parameter and creates a dictionary that keeps
the track of the alphabets present in the string along with its count.
Example if the string is OCCURRENCE then the dictionary must be
{"O":1,"C":3,"U":1,"R":2,"E":2,"N":1}