Python - Collections



Question 2     

What is the output of the following code

from collections import deque
str=""
a=['h','a','n','n']
d=deque(a)
d.appendleft('s')
d.append('u')
d.popleft()
d.pop()
d.pop()
print(str.join(d))






Question 3     

Observe the following code. What is the functionality of most_common() function in the below code?

from collections import Counter
l=[1,2,2,3,6,7,6,8,6,9,6,1,7,1,2,1,9,1]
c=Counter(l)
print(c.most_common())







Question 5     

Which of the following is not a specialized collections data types?






Question 6     

Which of the following statements is/are true about namedtuples? 1) namedtuple allows us to provide names to the elements. So we can access elements both by index value or by name 2)namedtuple field names can be any valid Python identifier 3)namedtuple helps us in writing better readable code. If the tuple has many values, using index becomes confusing. With namedtuple,






Question 7     

What is the output of the following code?

from collections import defaultdict
d = defaultdict(int)
d['kotlin'] = 1
d['python'] = 2
print(d['java'])






Question 9     

Which of the following can not have duplicate values in it?






Question 10     

what is the output of the following code?

from collections import Counter
myList = [1,1,2,3,4,5,3,2,3,4,2,1,2,3]
print Counter(myList).items()





Sign Up Page

Oops!!

To view the solution need to Login



Score : 0 / 0
L
o
a
d
i
n
g
.
.
.