Chapters
Python114 chapters

Exercises

itertools

3 tasks. Write the code, press Check, and the page runs it against a real Python interpreter.

Exercise 1

Flatten the groups into one list without building an intermediate list.

Python
groups = [[1, 2], [3], [4, 5]]
# print [1, 2, 3, 4, 5]
Exercise 2

Take the first five numbers from an endless counter.

Python
from itertools import count
# print [1, 2, 3, 4, 5]
Exercise 3

Print the difference between each pair of neighbouring readings.

Python
readings = [10, 12, 11, 15]
# print [2, -1, 4]