| Snaprecruit.com

| Snaprecruit.com

Interview question based on skill :

Take as many assements as you can to improve your validate your skill rating

Total Questions: 20

1. What is the output of the following code? a={1:"A",2:"B",3:"C"} b={4:"D",5:"E"} a.update(b) print(a)

Correct Answer is : {1: ‘A’, 2: ‘B’, 3: ‘C’, 4: ‘D’, 5: ‘E’}

2. What is the output of the following code? a={1:"A",2:"B",3:"C"} b=a.copy() b[2]="D" print(a)

Correct Answer is : {1: ‘A’, 2: ‘B’, 3: ‘C’}

3. What is the output of the following code? a={1:"A",2:"B",3:"C"} a.clear() print(a)

Correct Answer is : { }

4. Which of the following isn’t true about dictionary keys?

Correct Answer is : Keys must be integers

5. What is the output of the following code? a={1:5,2:3,3:4} a.pop(3) print(a)

Correct Answer is : {1: 5, 2: 3}

6. What is the output of the following code? a={1:5,2:3,3:4} print(a.pop(4,9))

Correct Answer is : 9

7. What is the output of the following code? a={1:"A",2:"B",3:"C"} for i in a: print(i,end=" ")

Correct Answer is : 37623

8. Execute the following in Python shell? >>> a={1:"A",2:"B",3:"C"} >>> a.items()

Correct Answer is : dict_items([(1, ‘A’), (2, ‘B’), (3, ‘C’)])

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

Correct Answer is : Values of a dictionary must be unique

10. What is the output of the following snippet of code? >>> a={1:"A",2:"B",3:"C"} >>> del a

Correct Answer is : del deletes the entire dictionary

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

Correct Answer is : Removes an arbitrary element

12. What is the output of the following snippet of code? total={} def insert(items): if items in total: total[items] += 1 else: total[items] = 1 insert('Apple') insert('Ball') insert('Apple') print (len(total))

Correct Answer is : 2

13. What is the output of the following snippet of code? a = {} a[1] = 1 a['1'] = 2 a[1]=a[1]+1 count = 0 for i in a: count += a[i] print(count)

Correct Answer is : 4

14. What is the output of the following snippet of code? numbers = {} letters = {} comb = {} numbers[1] = 56 numbers[3] = 7 letters[4] = 'B' comb['Numbers'] = numbers comb['Letters'] = letters print(comb)

Correct Answer is : {‘Numbers’: {1: 56, 3: 7}, ‘Letters’: {4: ‘B’}}

15. What is the output of the following snippet of code? test = {1:'A', 2:'B', 3:'C'} test = {} print(len(test))

Correct Answer is : 0

16. What is the output of the following snippet of code? test = {1:'A', 2:'B', 3:'C'} del test[1] test[1] = 'D' del test[2] print(len(test))

Correct Answer is : 2

17. What is the output of the following snippet of code? a = {} a[1] = 1 a['1'] = 2 a[1.0]=4 count = 0 for i in a: count += a[i] print(count)

Correct Answer is : 6

18. What is the output of the following snippet of code? a={} a['a']=1 a['b']=[2,3,4] print(a)

Correct Answer is : {‘b’: [2, 3, 4], ‘a’: 1}

19. What is the output of the following piece of code? >>>import collections >>> a=collections.Counter([1,1,2,3,3,4,4,4]) >>> a

Correct Answer is : Counter({4: 3, 1: 2, 3: 2, 2: 1})

20. What is the output of the following piece of code? >>>import collections >>> b=collections.Counter([2,2,3,4,4,4]) >>> b.most_common(1)

Correct Answer is : [(4, 3)].