logo

AQA A-Level Computer Science practice

What single value is produced by functools.reduce(lambda total, value: total + value, [4, 7, 2], 0)?

Try the question first, then check the answer and practise the same topic again.

At a glance

MCQ

Type

practice

Style

Topic

Writing functional programs

Exam-style question

Try this first

What single value is produced by functools.reduce(lambda total, value: total + value, [4, 7, 2], 0)?.

  1. A.9
  2. B.11
  3. C.13
  4. D.[4, 7, 2, 0]

Answer and explanation

Concise answer

13

Why this is correct

reduce repeatedly applies the combining function, starting with 0: ((0 + 4) + 7) + 2 = 13.

Use the concise answer above for a quick check, then reveal the full model answer and detailed explanation.

Common mistake

No common mistake is linked to this question yet.

Related flashcards

No flashcards are published for this page yet.

Related practice questions