Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > wishlist item: itertools.partition (WAS: Wishlist item: itertools.flatten)

Reply
Thread Tools

wishlist item: itertools.partition (WAS: Wishlist item: itertools.flatten)

 
 
Steven Bethard
Guest
Posts: n/a
 
      03-12-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> window / cons / fencepost / slice functions: +1
>
> (with a flag to say if you want to truncate or pad incomplete tuples
> at end of input sequence.
>
> http://aspn.activestate.com/ASPN/Coo.../Recipe/303279
> http://aspn.activestate.com/ASPN/Coo.../Recipe/303060
> http://aspn.activestate.com/ASPN/Coo.../Recipe/347689
>
> Probably more recipes in there, (and not CPAN-ish yet) but multiple
> submissions bespeak a certain need, i think.


Yes, also worth noting is the thread:

http://mail.python.org/pipermail/pyt...ry/263004.html

which concludes with:

from itertools import islice, chain, repeat

def partition(iterable, part_len):
itr = iter(iterable)
while 1:
item = tuple(islice(itr, part_len))
if len(item) < part_len:
raise StopIteration
yield item

def padded_partition(iterable, part_len, pad_val=None):
padding = repeat(pad_val, part_len-1)
itr = chain(iter(iterable), padding)
return partition(itr, part_len)

STeVe
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Firefox/TBird wishlist: printing font post2@this.ng Firefox 0 03-14-2006 01:38 PM
"Holiday Wishlist 2006" at XYZ Computing Silverstrand Front Page News 7 11-21-2005 01:44 AM
wishlist? Decrufting bookmark/fav manager Splibbilla Firefox 3 11-13-2005 03:03 AM
FireFox wishlist - add Newbie4Ever Firefox 1 09-26-2005 07:56 AM
Wishlist for a 10D successor? Lionel Digital Photography 15 08-23-2003 09:54 PM



Advertisments