ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-list
python-list
Re: switch recipe?
by Fredrik Lundh other posts by this author
Jul 13 2002 12:37PM messages near this date
Re: Moving list entries from one list to another | Re: Is count supposed to still work?
Mark McEahern

>  The thread on zip suggests the term "lockstep iteration."  I can't use map
>  or zip though because I have an unbounded iterator.  Of course, I could
>  easily bound that to the length of the finite iterator.

zip stops as soon as the first sequence runs out of items:

class over_and_over_again:
    def __init__(self, seq):
        self.seq = seq
        self.len = len(seq)
    def __getitem__(self, index):
        return self.seq[index % self.len]

print zip(range(12), over_and_over_again("spam"))

prints

[(0, 's'), (1, 'p'), (2, 'a'), (3, 'm'), (4, 's'), (5, 'p'),
(6, 'a'), (7, 'm'), (8, 's'), (9, 'p'), (10, 'a'), (11, 'm')]

</F> 


-- 
http://mail.python.org/mailman/listinfo/python-list

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved