Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #7032
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!weretis.net!feeder1.news.weretis.net!news.albasani.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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; 'received:10.127.143.53': 0.16; 'ternary': 0.16; 'this?': 0.19; 'maybe': 0.23; 'trying': 0.23; "doesn't": 0.25; 'function': 0.25; 'skip:[ 10': 0.26; 'thanks.': 0.27; "i'm": 0.27; 'subject:?': 0.29; 'received:mail.rr.com': 0.29; 'work:': 0.29; 'code,': 0.29; 'bit': 0.30; 'subject:How': 0.30; 'received:10.127': 0.30; 'received:10.127.143': 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; 'subject:this': 0.76; '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=+by6gQTzBq/Fycr5ZpaVeQ==:117 |
| X-Cloudmark-Score | 0 |
| Date | Sat, 4 Jun 2011 1:51:55 +0000 |
| From | <jyoung79@kc.rr.com> |
| To | python-list@python.org |
| Subject | How does this work? |
| 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.2463.1307239834.9059.python-list@python.org> (permalink) |
| Lines | 26 |
| NNTP-Posting-Host | 82.94.164.166 |
| X-Trace | 1307239834 news.xs4all.nl 49039 [::ffff:82.94.164.166]:49862 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:7032 |
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-sized-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
How does this work? <jyoung79@kc.rr.com> - 2011-06-04 01:51 +0000
Re: How does this work? Ben Finney <ben+python@benfinney.id.au> - 2011-06-05 13:37 +1000
Re: How does this work? Jon Clements <joncle@googlemail.com> - 2011-06-04 23:32 -0700
Re: How does this work? Ben Finney <ben+python@benfinney.id.au> - 2011-06-05 16:49 +1000
csiph-web