I have this function to split iterables into sublists by length, the fill values, and the direction of fill :
def split(v,size,fill=0,direction='right'):
if size == 0: return []
lenv = len(v)
count = lenv/size
remainder = lenv%size
result = []
for i in range(0,lenv-remainder,size):
result.append(v[i:i+size])
if remainder > 0:
if direction == 'right':
result.append(v[count*size:] + [fill] * (size-remainder))
else:
result.append([fill] * (size-remainder) + v[count*size:])
return result
Because I like one liners I want to rewrite it with map, but I don't understand how to. I have this so far :
def j1(a,b):
return a + b
def j2(a,b):
return b
def split2(v,size,fill=0):
map(j1,(x for x in map(j2,v)))
I have no idea. Any hints?