Is there any simple way to convert [1,2,3,4,5,6,7,8,9]
to [[1,2,3],[4,5,6],[7,8,9]]
, without an explicit for
loop?
>>> x = [1,2,3,4,5,6,7,8,9]
>>> zip(*[iter(x)]*3)
[(1, 2, 3), (4, 5, 6), (7, 8, 9)]
How does zip(*[iter(s)]*n)
work in Python?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With