. , calendar
:
In [11]: months = [calendar.monthrange(2017, m)[1] for m in range(1, 13)]
In [12]: months
Out[12]: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
, . , calendar.isleap()
- True.
, slice , int()
statistics.mean()
:
In [17]: from statistics import mean
In [18]: from itertools import islice
In [19]: [mean(map(int, islice(the_file, mdays))) for mdays in months]
Out[19]: [15, 44.5, 74, 104.5, 135, 165.5, 196, 227, 257.5, 288, 318.5, 349]
the_file
In [13]: from io import StringIO
In [14]: the_file = StringIO()
In [15]: the_file.writelines(map('{}\n'.format, range(365)))
In [16]: the_file.seek(0)
Out[16]: 0