Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #7083

RE: Lambda question

Date 2011-06-06 13:42 +0000
From <jyoung79@kc.rr.com>
Subject RE: Lambda question
Newsgroups comp.lang.python
Message-ID <mailman.2488.1307367811.9059.python-list@python.org> (permalink)

Show all headers | View raw


>>>>> f = lambda x, n, acc=[]: f(x[n:], n, acc+[(x[:n])]) if x else acc

> Packing tail recursion into one line is bad for both understanding and 
> refactoring. Use better names and a docstring gives
> 
> def group(seq, n):
>    'Yield from seq successive disjoint slices of length n plus the 
> remainder'
>    for i in range(0,len(seq), n):
>      yield seq[i:i+]
> 
> -- 
> Terry Jan Reedy

Thank you all very much for this incredible help!  The original code 
now makes sense, and I was thrilled to see better and more efficient 
ways of doing this.  Thanks for taking the time to share your 
thoughts as well as the excellent detail everyone shared…  I really 
appreciate it!

Jay

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

RE: Lambda question <jyoung79@kc.rr.com> - 2011-06-06 13:42 +0000

csiph-web