On Mon, 7 Feb 2005, Tony Cappellini wrote:
> > Here's a quick function that should force a certain length on an > > iterator: > > > > ### > > def ipad(iterable, length, sentinel=None): > > i = 0 > > for thing in iterable: > > yield thing > > i = i + 1 > > while i < length: > > yield sentinel > > i = i + 1 > > ### > > BTW, is your def ipad() function the 20gb, 40gb, or 60gb model ? :-) Hi Tony, Oh, I had some terrible puns I was going to use in the last message. Here's one, just for your amusement: ### import sys def ipad_maxi(iterable, sentinel=None): """Applies a maximum ipad()ding on a given iterable.""" return ipad(iterable, sys.maxint, sentinel) ### But getting back on topic: I like Kent's solution with map() much better than my own. I had completely forgotten that map() had a special case that applies directly to what you're trying to do. Best of wishes to you! _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor