Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
What does this program show? Say it before you run it.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, compare your working with the solution.
Plan. An iterator is used up after one pass. A list gives a fresh iterator each time.
sum(it): 1 + 2 + 3 = 6.sum(it) again: the iterator is used up, so there is nothing to add: 0.sum(numbers): 6. 4. sum(numbers) again: still 6, because the list is not used up.max(squares): the squares are 1, 4, 9, so 9.max(squares, default="none"): the generator is used up, so there is nothing to compare. Without the default, max would raise a ValueError. With it, it gives none.Answer: 6, 0, 6, 6, 9, none.
Log in to join the discussion.
Loading…