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


Groups > comp.lang.python > #7012

Lambda question

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!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <jyoung79@kc.rr.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.041
X-Spam-Evidence '*H*': 0.92; '*S*': 0.00; 'lost.': 0.09; 'operator,': 0.09; '>>>': 0.12; 'guessing': 0.16; 'handy': 0.16; 'lambda': 0.16; 'ternary': 0.16; 'this?': 0.19; 'maybe': 0.23; 'subject:question': 0.23; 'trying': 0.23; "doesn't": 0.25; 'function': 0.25; 'skip:[ 10': 0.26; 'thanks.': 0.27; "i'm": 0.27; 'received:mail.rr.com': 0.29; 'work:': 0.29; 'code,': 0.29; 'bit': 0.30; 'received:10.127': 0.30; 'received:75.180': 0.30; 'received:75.180.132': 0.30; 'received:cdptpa-omtalb.mail.rr.com': 0.30; 'looks': 0.31; 'sort': 0.31; 'equal': 0.31; 'anyone': 0.32; 'does': 0.33; 'to:addr:python-list': 0.33; 'list': 0.33; 'curious': 0.35; 'else': 0.35; 'received:75': 0.35; 'received:rr.com': 0.36; 'certain': 0.36; 'something': 0.37; 'could': 0.38; 'but': 0.38; 'some': 0.38; 'explain': 0.39; 'list,': 0.39; 'to:addr:python.org': 0.39; 'totally': 0.40; 'from:no real name:2**0': 0.61; 'huge': 0.62; 'link': 0.64; 'website': 0.66; 'share': 0.67; 'jay': 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=8mDY8c80ZOa76EOwICuS+E2YRQjxDgO9xqUnRMONc7w= c=1 sm=0 a=IkcTkHD0fZMA:10 a=uPZiAMpXAAAA:8 a=Lh48n3D_W5-xa3zBA_cA:9 a=QEXdDO2ut3YA:10 a=NTOc0A1UbkXN2rBMmhC+BQ==:117
X-Cloudmark-Score 0
Date Sat, 4 Jun 2011 17:46:23 +0000
From <jyoung79@kc.rr.com>
To python-list@python.org
Subject Lambda question
MIME-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 7bit
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 <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2454.1307209587.9059.python-list@python.org> (permalink)
Lines 27
NNTP-Posting-Host 82.94.164.166
X-Trace 1307209587 news.xs4all.nl 49184 [::ffff:82.94.164.166]:41481
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:7012

Show key headers only | View raw


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 | NextNext in thread | Find similar | Unroll thread


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