I have a simple list splitting question:
given a nested list like this:
x = [[1,4,3],[2,3,5,1,3,52,3,5,2,1],[2]]
I want to further split any element(sub-list) longer than 3, and whose length is a multiple of 3 or 3n+1 into sub-lists of length 3, except for the last chunk, so the result I want is:
x2 = [[1,4,3], [2,3,5],[1,3,52],[3,5,2,1],[2]]
I think it can be done with itertools.groupby and/or yield functions... but couldn't put together the details >> a_function(x)...
splits = [ a_function(x) if len(x)>3 and (len(x) % 3 == 0 or len(x) % 3 == 1) else x for x in x]
Could anyone kindly give me some pointers? Thanks so much.