Dictionary Assignment Qus
Dictionary Assignment Qus
1. The ____________ is unordered collections with elements in the form of a key:value pairs.
2. Dictionaries are mutable. (True/False)
3. The key can be considered as an index into the dictionary. (True/False)
4. Which of the brackets are used to define the dictionary?
1. Round Bracket ()
2. Square Bracket []
3. Curly Bracket {}
4. Angular Bracket <>
5. The key and value is separated by ___________ symbol in the dictionary.
1. Comma ,
2. Semi-Colon ;
3. Dash –
4. Colon :
6. The dictionary key can be mutable types. (True/False)
7. Which of the following is the correct statement to access the value of an element of dictionary
through key?
1. <dictionary> [<key>]
2. <dictionary> <key>
3. <dictionary>.<key>
4. <dictionary>-<key>
8. What happens when the user is trying to access a that doesn’t exist?
1. Return None
2. Return Garbage Value
3. Return Last Value
4. Return Error
9. Tuple can be used as a key in the dictionary. (True/False)
10. The _________ method returns all the keys defined in the dictionary in form of a list.
11. The _________ method returns all the keys defined in the dictionary in form of a list.
12. The keys and values both must be unique for the dictionaries. (True/False)
13. The in and not in operator will check the presence of keys only, not the value. (True/False)
14. The statements <dictionary>.get(<key>) and <dictionary>.[<key>] are similar. (True/False)
15. Which of the method is used to create a new dictionary from a sequence with all the keys and a
common value?
1. insert()
2. fromkeys()
3. update()
4. setdefault()
16. Which of the following is method removes and returns a key:value pair that follows LIFO order?
1. pop()
2. remove()
3. popitem()
A.1
4. delete()
17. What is the output of this code: d ={‘Ind’:’Virat Kohli’,’MS Dhoni’:’Ind’,’NZ’:’Kane Williamson’};
print(d[‘Ind’])
1. Virat Kohli
2. MS Dhoni
3. Ind
4. All of these
18. What is the output of this code:d={‘Virat Kohli’:1,’Steve Smith’:2,’Babar Azam’:3,’Faf Du
Plesis’:4};print(d[3])
1. ‘Babar Azam’:3
2. ‘Faf Du Plesis’:4
3. Babar Azam
4. Error
19. The sorted() function cannot work with a dictionary. (True/False)
20. A dictionary can have repeated keys. (True/False)
1. What do you mean by a dictionary? Explain with the context of key:value pair?
2. What are the characteristics of a dictionary that differs it from other collections like lists, tuples,
sets of python?
3. How you can access keys and values simultaneously? Explain with the example.
4. What are the different ways to create a dictionary? Elaborate your answer with an example.
5. How to add, update and delete element from the dictionary? Illustrate your answer with an
example.
6. How to access items, keys and values from a dictionary? Describe the answer with an example.
7. When are dictionaries more useful than lists ?
Programs
1. Write a program to input total number of sections and class teacher’s name in 11th class and
display all information on the output screen.
2. Write a Python program to input ‘n’ names and phone numbers to store it in a dictionary and to
input any name and to print the phone number of the particular name.
3. Write the code to input any 5 years population of any city and print it on the screen.
4. Write a code to create customer’s list with their number & name and delete any particular
customer using his /her number.
5. Write a program to input your friends’ names and their Phone Numbers and store them in the
dictionary as the key-value pair. Perform the following operations on the dictionary:
A.2
a) Display the name and phone number of all your friends
b) Add a new key-value pair in this dictionary and display the modified dictionary
c) Delete a particular friend from the dictionary
d) Modify the phone number of an existing friend
e) Check if a friend is present in the dictionary or not
f) Display the dictionary in sorted order of names
6. Consider the following dictionary stateCapital:
stateCapital = {"AndhraPradesh":"Hyderabad","Bihar":"Patna","Maharashtra":"Mumbai",
"Rajasthan":"Jaipur"}
Find the output of the following statements:
print(stateCapital.get("Bihar"))
print(stateCapital.keys())
print(stateCapital.values())
print(stateCapital.items())
print(len(stateCapital))
print("Maharashtra" in stateCapital)
print(stateCapital.get("Assam"))
A.3
A.4