Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion A gnarly little python loop
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Cameron Simpson  
View profile  
 More options Nov 11 2012, 3:48 am
Newsgroups: comp.lang.python
From: Cameron Simpson <c...@zip.com.au>
Date: Sun, 11 Nov 2012 19:48:36 +1100
Local: Sun, Nov 11 2012 3:48 am
Subject: Re: A gnarly little python loop
On 11Nov2012 08:56, Stefan Behnel <stefan...@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 <c...@zip.com.au>

In an insane society, the sane man must appear insane.
        - Keith A. Schauer <ke...@balrog.dseg.ti.com>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.