How to group list items into tuple?
list, python, tuples
Solution
>>> a
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> [tuple(a[i:i+5]) for i in range(0, len(a), 5)]
[(0, 1, 2, 3, 4), (5, 6, 7, 8, 9)]
Problem
I have a list of numbers, how can I group every `n` numbers into a tuple? For example, if I have a list `a = range(10)` and I want to group every 5 items into a tuple, so: ``` b = [(0,1,2,3,4),(5,6,7,8,9)] ``` How can I do this? I also want to raise an error if `len(a)` is not an integer multiple of `n`.