G
Guest
I was surfing around looking for a way to split a list into equal sections. I came
upon this algorithm:
(http://stackoverflow.com/questions/...ist-into-evenly-sized-chunks-in-python/312644)
It doesn't work with a huge list, but looks like it could be handy in certain
circumstances. I'm trying to understand this code, but am totally lost. I
know a little bit about lambda, as well as the ternary operator, but how
does this part work:
Is that some sort of function call, or something else? I'm guessing it works
recursively?
Just curious if anyone could explain how this works or maybe share a link
to a website that might explain this?
Thanks.
Jay
upon this algorithm:
['Hal', 'lo ', 'Wel', 't']f = lambda x, n, acc=[]: f(x[n:], n, acc+[(x[:n])]) if x else acc
f("Hallo Welt", 3)
(http://stackoverflow.com/questions/...ist-into-evenly-sized-chunks-in-python/312644)
It doesn't work with a huge list, but looks like it could be handy in certain
circumstances. I'm trying to understand this code, but am totally lost. I
know a little bit about lambda, as well as the ternary operator, but how
does this part work:
['dud', 'e']f('dude'[3:], 3, []+[('dude'[:3])])
Is that some sort of function call, or something else? I'm guessing it works
recursively?
Just curious if anyone could explain how this works or maybe share a link
to a website that might explain this?
Thanks.
Jay