Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #33122
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <cameron@cskk.homeip.net> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'sane': 0.09; 'def': 0.10; 'subject:python': 0.11; 'steve': 0.13; 'cleaner': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'inaccessible': 0.16; 'keith': 0.16; 'message-id:@cskk.homeip.net': 0.16; 'readable': 0.16; 'received:202.125.174': 0.16; 'received:202.125.174.133': 0.16; 'received:boardofstudies.nsw.edu.au': 0.16; 'received:cskk.homeip.net': 0.16; 'received:edu.au': 0.16; 'received:harvey.boardofstudies.nsw.edu.au': 0.16; 'received:homeip.net': 0.16; 'received:nsw.edu.au': 0.16; 'roy': 0.16; 'simpson': 0.16; 'wrote:': 0.17; 'skip:i 40': 0.17; 'stefan': 0.17; "i'd": 0.22; 'seems': 0.23; 'header:In-Reply- To:1': 0.25; 'header:User-Agent:1': 0.26; 'appear': 0.26; 'this?': 0.28; 'code': 0.31; 'to:addr:python-list': 0.33; 'nov': 0.35; 'pm,': 0.35; 'too.': 0.35; 'there': 0.35; 'but': 0.36; 'received:au': 0.36; 'charset:us-ascii': 0.36; 'subject:: ': 0.38; 'some': 0.38; 'page': 0.38; 'to:addr:python.org': 0.39; 'think': 0.40; 'your': 0.60; 'content-disposition:inline': 0.60; 'times': 0.63; 'smith': 0.71; 'insane': 0.93 |
| Date | Sun, 11 Nov 2012 19:48:36 +1100 |
| From | Cameron Simpson <cs@zip.com.au> |
| To | python-list@python.org |
| Subject | Re: A gnarly little python loop |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Content-Disposition | inline |
| In-Reply-To | <k7nlmo$1v6$2@ger.gmane.org> |
| User-Agent | Mutt/1.5.21 (2010-09-15) |
| References | <k7nlmo$1v6$2@ger.gmane.org> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| 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.3555.1352623728.27098.python-list@python.org> (permalink) |
| Lines | 33 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1352623728 news.xs4all.nl 6855 [2001:888:2000:d::a6]:48032 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:33122 |
Show key headers only | View raw
On 11Nov2012 08:56, Stefan Behnel <stefan_ml@behnel.de> wrote:
| Steve Howell, 11.11.2012 04:03:
| > On Nov 10, 2:58 pm, Roy Smith <r...@panix.com> wrote:
| >> page = 1
| >> while 1:
| >> r = api.GetSearch(term="foo", page=page)
| >> if not r:
| >> break
| >> for tweet in r:
| >> process(tweet)
| >> page += 1
| >>
| >> It works, but it seems excessively fidgety. Is there some cleaner way
| >> to refactor this?
| >
| > I think your code is perfectly readable and clean, but you can flatten
| > it like so:
| >
| > def get_tweets(term, get_page):
| > page_nums = itertools.count(1)
| > pages = itertools.imap(api.getSearch, page_nums)
| > valid_pages = itertools.takewhile(bool, pages)
| > tweets = itertools.chain.from_iterable(valid_pages)
| > return tweets
|
| I'd prefer the original code ten times over this inaccessible beast.
Me too.
--
Cameron Simpson <cs@zip.com.au>
In an insane society, the sane man must appear insane.
- Keith A. Schauer <keith@balrog.dseg.ti.com>
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Re: A gnarly little python loop Cameron Simpson <cs@zip.com.au> - 2012-11-11 19:48 +1100
Re: A gnarly little python loop Paul Rubin <no.email@nospam.invalid> - 2012-11-11 01:09 -0800
Re: A gnarly little python loop Peter Otten <__peter__@web.de> - 2012-11-11 10:54 +0100
Re: A gnarly little python loop Steve Howell <showell30@yahoo.com> - 2012-11-11 09:16 -0800
Re: A gnarly little python loop Steve Howell <showell30@yahoo.com> - 2012-11-11 09:16 -0800
Re: A gnarly little python loop Steve Howell <showell30@yahoo.com> - 2012-11-11 09:29 -0800
Re: A gnarly little python loop Peter Otten <__peter__@web.de> - 2012-11-11 19:34 +0100
Re: A gnarly little python loop Steve Howell <showell30@yahoo.com> - 2012-11-11 11:16 -0800
Re: A gnarly little python loop Cameron Simpson <cs@zip.com.au> - 2012-11-12 11:43 +1100
Re: A gnarly little python loop Steve Howell <showell30@yahoo.com> - 2012-11-11 17:38 -0800
Re: A gnarly little python loop Roy Smith <roy@panix.com> - 2012-11-11 14:23 -0500
csiph-web