Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.032 X-Spam-Evidence: '*H*': 0.94; '*S*': 0.00; 'slices': 0.07; 'terry': 0.07; 'recursion': 0.09; 'successive': 0.09; 'tail': 0.09; 'def': 0.12; 'docstring': 0.16; 'lambda': 0.16; 'n):': 0.16; 'reedy': 0.16; 'yield': 0.19; 'jan': 0.20; 'subject:question': 0.23; 'code': 0.24; 'thanks': 0.28; 'received:mail.rr.com': 0.29; 'received:10.127': 0.30; 'received:75.180': 0.30; 'received:75.180.132': 0.30; 'received:cdptpa-omtalb.mail.rr.com': 0.30; 'this.': 0.31; 'to:addr:python-list': 0.33; 'thank': 0.35; 'sense,': 0.35; 'else': 0.35; 'received:75': 0.35; 'received:rr.com': 0.36; 'ways': 0.37; 'subject:: ': 0.38; 'doing': 0.39; 'it!': 0.39; 'to:addr:python.org': 0.39; 'everyone': 0.40; 'really': 0.40; 'more': 0.60; 'your': 0.60; 'from:no real name:2**0': 0.61; 'taking': 0.64; 'incredible': 0.65; 'plus': 0.65; 'share': 0.67; 'jay': 0.84; 'packing': 0.84 Authentication-Results: cdptpa-omtalb.mail.rr.com smtp.user=jyoung79@kc.rr.com; auth=pass (LOGIN) X-Authority-Analysis: v=1.1 cv=aeMH4JcVOnVr0LmJAzqEvfnmJyuaZufWdlng4HTRGCk= c=1 sm=0 a=IkcTkHD0fZMA:10 a=pucoitdqsAzEVdgCw3AA:9 a=QEXdDO2ut3YA:10 a=kPDWxe0Y+AmzkgVshK7X5A==:117 X-Cloudmark-Score: 0 Date: Mon, 6 Jun 2011 13:42:15 +0000 From: To: python-list@python.org Subject: RE: Lambda question MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Priority: 3 (Normal) Sensitivity: Normal X-Originating-IP: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 22 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1307367812 news.xs4all.nl 49179 [::ffff:82.94.164.166]:43504 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:7083 >>>>> f =3D lambda x, n, acc=3D[]: f(x[n:], n, acc+[(x[:n])]) if x else acc > Packing tail recursion into one line is bad for both understanding and=20 > refactoring. Use better names and a docstring gives >=20 > def group(seq, n): > 'Yield from seq successive disjoint slices of length n plus the=20 > remainder' > for i in range(0,len(seq), n): > yield seq[i:i+] >=20 > --=20 > Terry Jan Reedy Thank you all very much for this incredible help! The original code=20 now makes sense, and I was thrilled to see better and more efficient=20 ways of doing this. Thanks for taking the time to share your=20 thoughts as well as the excellent detail everyone shared=E2=80=A6 I really= =20 appreciate it! Jay