| 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 will be the output? def example(L): ''' (list) -> list ''' i = 0 result = [] while i < len(L): result.append(L[i]) i = i + 3 return result

Correct Answer is : Return a list containing every third item from L starting at index 0

2. What will be the output? veggies = ['carrot', 'broccoli', 'potato', 'asparagus']veggies.insert(veggies.index('broccoli'), 'celery')print(veggies)

Correct Answer is : [‘carrot’, ‘celery’, ‘broccoli’, ‘potato’, ‘asparagus’] Correct 1.00

3. What will be the output? >>>m = [[x, x + 1, x + 2] for x in range(0, 3)]

Correct Answer is : [[0, 1, 2], [1, 2, 3], [2, 3, 4]].

4. How many elements are in m? m = [[x, y] for x in range(0, 4) for y in range(0, 4)]

Correct Answer is : 16

5. What will be the output? values = [[3, 4, 5, 1], [33, 6, 1, 2]] v = values[0][0]for row in range(0, len(values)): for column in range(0, len(values[row])): if v < values[row][column]: v = values[row][column] print(v)

Correct Answer is : 33

6. What will be the output? values = [[3, 4, 5, 1], [33, 6, 1, 2]] v = values[0][0]for lst in values: for element in lst: if v > element: v = element print(v)

Correct Answer is : 1

7. What will be the output? values = [[3, 4, 5, 1 ], [33, 6, 1, 2]] for row in values: row.sort() for element in row: print(element, end = " ") print()

Correct Answer is : The program prints two rows 1 3 4 5 followed by 1 2 6 33

8. What is the output? matrix = [[1, 2, 3, 4], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15]] for i in range(0, 4): print(matrix[i][1], end = " ")

Correct Answer is : 2 5 9 13

9. What will be the output? def m(list): v = list[0] for e in list: if v < e: v = e return v values = [[3, 4, 5, 1], [33, 6, 1, 2]] for row in values: print(m(row), end = " ")

Correct Answer is : 5 33

10. What will be the output? data = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]] print(data[1][0][0])

Correct Answer is : 5

11. What will be the output? data = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]] def ttt(m): v = m[0][0]  for row in m: for element in row: if v < element: v = element  return v print(ttt(data[0]))

Correct Answer is : 4

12. What will be the output? points = [[1, 2], [3, 1.5], [0.5, 0.5]]points.sort()print(points)

Correct Answer is : [[0.5, 0.5], [1, 2], [3, 1.5]].

13. What is the output of the following code? a=[10,23,56,[78]] b=list(a) a[3][0]=95 a[1]=34 print(b)

Correct Answer is : [10,23,56,[95]].

14. What does the following piece of code do? print(list(zip((1,2,3),('a'),('xxx','yyy')))) print(list(zip((2,4),('b','c'),('yy','xx'))))

Correct Answer is : [(1, ‘a’, ‘xxx’)].

15. What is the output of the following code? import copy a=[10,23,56,[78]] b=copy.deepcopy(a) a[3][0]=95 a[1]=34 print(b)

Correct Answer is : [10,23,56,[78]].

16. What is the output of the following piece of code? s="[email protected]@[email protected]" a=list(s.partition("@")) print(a) b=list(s.split("@",3)) print(b)

Correct Answer is : [‘a’,’@’,’[email protected]@d’].

17. What is the output of the following code? a=[1,2,3,4] b=[sum(a[0:x+1]) for x in range(0,len(a))] print(b)

Correct Answer is : [1,3,6,10].

18. What is the output of the following code? a="hello" b=list((x.upper(),len(x)) for x in a) print(b)

Correct Answer is : [(‘H’, 1), (‘E’, 1), (‘L’, 1), (‘L’, 1), (‘O’, 1)].

19. What is the output of the following code? a=[1,2,3,4] b=[sum(a[0:x+1]) for x in range(0,len(a))] print(b)

Correct Answer is : [1,3,6,10].

20. What is the output of the following code? a=[[]]*3 a[1].append(7) print(a)

Correct Answer is : [[7], [7], [7]].