41. What will be the output of the following Python code?
>>> a=dict()
>>> a[1]
>>> a=dict()
>>> a[1]
42. What will be the output of the following Python code snippet?
a={1:"A",2:"B",3:"C"}
a.setdefault(4,"D")
print(a)
a={1:"A",2:"B",3:"C"}
a.setdefault(4,"D")
print(a)
43. What will be the output of the following Python code?
a={1:5,2:3,3:4}
print(a.pop(4,9))
a={1:5,2:3,3:4}
print(a.pop(4,9))
44. 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
>>> import collections
>>> a=collections.Counter([3,3,4,5])
>>> b=collections.Counter([3,4,4,5,5,5])
>>> a&b
45. What will be the output of the following Python code snippet?
d1 = {"john":40, "peter":45}
d2 = {"john":466, "peter":45}
d1 > d2
d1 = {"john":40, "peter":45}
d2 = {"john":466, "peter":45}
d1 > d2
46. 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)
>>>import collections
>>> b=collections.Counter([2,2,3,4,4,4])
>>> b.most_common(1)
47. Suppose d = {"john":40, "peter":45}. To obtain the number of entries in dictionary which command do we use?
48. The following Python code is invalid.
class demo(dict):
def __test__(self,key):
return []
a = demo()
a['test'] = 7
print(a)
class demo(dict):
def __test__(self,key):
return []
a = demo()
a['test'] = 7
print(a)
49. What will be the output of the following Python code?
a={}
a[2]=1
a[1]=[2,3,4]
print(a[1][1])
a={}
a[2]=1
a[1]=[2,3,4]
print(a[1][1])
50. What will be the output of the following Python code?
>>> import collections
>>> a=dict()
>>> a=collections.defaultdict(str)
>>> a['A']
>>> import collections
>>> a=dict()
>>> a=collections.defaultdict(str)
>>> a['A']