If you find any wrong answers, please comment below and we will get back to you.

1) Consider the following Python function.

def mystery(l):
  if len(l) < 2:
    return (l)
  else:
    return (mystery(l[1:]) + [l[0]])

What does mystery([17,12,41,28,25]) return?

Answer(s) : [25, 28, 41, 12, 17]

2) What is the value of triples after the following assignment?

triples = [ (x,y,z) for x in range(1,4) for y in range(x,4) for z in range(y,4) if x+y <= z ]

Answer(s) : [(1, 1, 2), (1, 1, 3), (1, 2, 3)]

3) Consider the following dictionary.
a) marks[“Exams”][“Suresh”].extend([44])
b) marks[“Exams”][“Suresh”].append(44)
c) marks[“Exams”][“Suresh”] = [44]
d) marks[“Exams”][“Suresh”][0:] = [44]

Answer(s) : (c) marks["Exams"]["Suresh"] = [44]

4) Assume that grandslams has been initialized as an empty dictionary:

grandslams = {}

a) grandslams[(“Federer”,”Wimbledon”)] = 8
b) grandslams[[“Federer”,”Wimbledon”]] = 8
c) grandslams[“Federer, Wimbledon”] = 8
d) grandslams[“Federer”] = [“Wimbledon”,8]

Answer(s) : (b) grandslams[["Federer","Wimbledon"]] = 8
Reason : TypeError: unhashable type: 'list'

[quads id=1]