My Report

Python Dictionary Test – 4


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?

>>> a={i: 'A' + str(i) for i in range(5)}
>>> a

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

>>> import collections
>>> a=collections.OrderedDict((str(x),x) for x in range(3))
>>> a

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

>>> a={}
>>> a.fromkeys([1,2,3],"check")

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

>>> a=dict()
>>> a[1]

5. If b is a dictionary, what does any(b) do?

6. The following Python code is invalid.

class demo(dict):
  def __test__(self,key):
    return []
a = demo()
a['test'] = 7
print(a)

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

>>> import collections
>>> a=dict()
>>> a=collections.defaultdict(str)
>>> a['A']

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

>>> import collections
>>> b=dict()
>>> b=collections.defaultdict(lambda: 7)
>>> b[4]

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

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

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

>>> a={"a":1,"b":2,"c":3}
>>> b=dict(zip(a.values(),a.keys()))
>>> b

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

>>> a={'B':5,'A':9,'C':7}
>>> sorted(a)

12. What will be the output of the following Python code?

count={}
count[(1,2,4)] = 5
count[(4,2,1)] = 7
count[(1,2)] = 6
count[(4,2,1)] = 2
tot = 0
for i in count:
    tot=tot+count[i]
print(len(count)+tot)

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

>>> b={}
>>> all(b)

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

>>> a={i: i*i for i in range(6)}
>>> a

15. What will be the output of the following Python code?

>>> import collections
>>> a=dict()
>>> a=collections.defaultdict(int)
>>> a[1]

 

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.