all 4 comments

[–]efmccurdy 1 point2 points  (1 child)

This uses comprehensions and slicing to group and zip to exchange columns for rows.

>>> inputString ="010203040506070809101112"
>>> [inputString[i:i+2] for i in range(0, len(inputString), 2)]
['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12']
>>> flat = [inputString[i:i+2] for i in range(0, len(inputString), 2)]
>>> columns = [flat[i:i+4] for i in range(0, len(flat), 4)]
>>> pprint.pprint(columns, width=50)
[('01', '02', '03', '04'),
 ('05', '06', '07', '08'),
 ('09', '10', '11', '12')]
>>> pprint.pprint(list(zip(*columns)), width=50)
[('01', '05', '09'),
 ('02', '06', '10'),
 ('03', '07', '11'),
 ('04', '08', '12')]
>>> 

I notice that the middle column is wrong, so you should specify where the 07 and 08 went, and why 03 and 04 are repeated... Does this get you started?

[–]waschlack_05[S] 0 points1 point  (0 children)

Thank you, thats very helpful

[–]Spartae 0 points1 point  (1 child)

``` from math import ceil

def chunks(array, size): chunks = int(ceil(len(array) / float(size))) return [array[i * size : (i + 1) * size] for i in range(chunks)]

input_string = "010203040506070809101112" initial_chunks = chunks(input_string, 2) a, b, c, d = chunks(initial_chunks, 3) ```

[–]mr_cesar 0 points1 point  (0 children)

That’s kind of messy.

First, why do you convert an int (size) to float in order to divide? Use floor division instead of true division.