Skip to content

Question 7

Evaluate:

[[7, 11], 42][0] + [2, 4]
Hint

Work out the expression from left to right in stages.

Solution

With lists, the + operator allow concatenation of 2 lists. This DOES NOT work like: [a, b] + [c, d] = [a+c, b+d].

[[7, 11], 42][0] + [2, 4]
= [7, 11] + [2, 4] # concatenate the two lists together, [2, 4] does not form 1 element by itself
= [7, 11, 2, 4] # not [7, 11, [2, 4]]

NOTE: [7, 11] + [2, 4] == [7, 11].extend([2, 4])

Answer
[7, 11, 2, 4]