Lambda question

jyoung79 at kc.rr.com jyoung79 at kc.rr.com
Mon Jun 6 09:42:15 EDT 2011


>>>>> 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


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /