My Report

Python Dictionary Test – 3


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

1. What will be the output of the following Python code snippet?

a = {}
a[1] = 1
a['1'] = 2
a[1.0]=4
count = 0
for i in a:
    count += a[i]
print(count)

2. What will be the output of the following Python code snippet?

test = {1:'A', 2:'B', 3:'C'}
test = {}
print(len(test))

3. What will be the output of the following Python code snippet?

>>> import collections
>>> a=collections.Counter([2,2,3,3,3,4])
>>> b=collections.Counter([2,2,3,4,4])
>>> a|b

4. What will be the output of the following Python code snippet?

a = {}
a[1] = 1
a['1'] = 2
a[1]=a[1]+1
count = 0
for i in a:
    count += a[i]
print(count)

5. What will be the output of the following Python code snippet?

numbers = {}
letters = {}
comb = {}
numbers[1] = 56
numbers[3] = 7
letters[4] = 'B'
comb['Numbers'] = numbers
comb['Letters'] = letters
print(comb)

6. What will be the output of the following Python code snippet?

>>>import collections
>>> b=collections.Counter([2,2,3,4,4,4])
>>> b.most_common(1)

7. What will be the output of the following Python code snippet?

>>>import collections
>>> a=collections.Counter([1,1,2,3,3,4,4,4])
>>> a

8. What will be the output of the following Python code snippet?

test = {1:'A', 2:'B', 3:'C'}
del test[1]
test[1] = 'D'
del test[2]
print(len(test))

9. What will be the output of the following Python code snippet?

total={}
def insert(items):
    if items in total:
        total[items] += 1
    else:
        total[items] = 1
insert('Apple')
insert('Ball')
insert('Apple')
print (len(total))

10. What will be the output of the following Python code snippet?

>>> import collections
>>> a=collections.Counter([3,3,4,5])
>>> b=collections.Counter([3,4,4,5,5,5])
>>> a&b

11. What will be the output of the following Python code snippet?

a={}
a['a']=1
a['b']=[2,3,4]
print(a)

12. If a is a dictionary with some key-value pairs, what does a.popitem() do?

13. What will be the output of the following Python code snippet?

>>>import collections
>>> b=collections.Counter([2,2,3,4,4,4])
>>> b.most_common(1)

14. What will be the output of the following Python code snippet?

>>> a={1:"A",2:"B",3:"C"}
>>> del a

15. Which of the statements about dictionary values if false?


 

Start practicing “1000 MCQs on Python”, and once you are ready, you can take tests on all topics by attempting our “Python Test Series”.

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.