Possible Duplicate:
How do you split a list into evenly sized chunks in Python?
Merge two lists in python?
Original data in array:
a = ['1', '2', '3', '4', '5', '6', '7', '8', '9']
Desired output:
['1 2 3', '4 5 6', '7 8 9']
I know using the while
statement is inefficient, so I need help in this.
[' '.join(a[i:i+3]) for i in range(0, len(a), 3)]
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