Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #7012
| Date | 2011-06-04 17:46 +0000 |
|---|---|
| From | <jyoung79@kc.rr.com> |
| Subject | Lambda question |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2454.1307209587.9059.python-list@python.org> (permalink) |
I was surfing around looking for a way to split a list into equal sections. I
came upon this algorithm:
>>> f = lambda x, n, acc=[]: f(x[n:], n, acc+[(x[:n])]) if x else acc
>>> f("Hallo Welt", 3)
['Hal', 'lo ', 'Wel', 't']
http://stackoverflow.com/questions/312443/how-do-you-split-a-list-into-evenly-s
ized-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:
>>> f('dude'[3:], 3, []+[('dude'[:3])])
['dud', 'e']
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
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Lambda question <jyoung79@kc.rr.com> - 2011-06-04 17:46 +0000
Re: Lambda question Mel <mwilson@the-wire.com> - 2011-06-04 14:21 -0400
Re: Lambda question Alain Ketterlin <alain@dpt-info.u-strasbg.fr> - 2011-06-05 11:31 +0200
Re: Lambda question Terry Reedy <tjreedy@udel.edu> - 2011-06-05 14:33 -0400
Re: Lambda question rusi <rustompmody@gmail.com> - 2011-06-06 10:29 -0700
Re: Lambda question Terry Reedy <tjreedy@udel.edu> - 2011-06-06 21:56 -0400
csiph-web