I have a list of objects representing widgets. Each widget object has a manufactured DateTime field that holds the date and time when the widget was made. All the widgets in the list were manufactured in a particular year.
I would like to get a list with the total widgets manufactured each month – e.g.:
>>> totals
[1, 5, 819, 187, 1, 5, 15, 9, 13, 77, 54, 22]
So in the above list there were 819 widgets made in March.
What’s a pythonic way of doing this?
The indices of
totalsare in the range 0 to 11, while months usually are in the range 1 to 12, so we need the- 1.An alternative in Python 2.7 or 3.1 or above: