<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Sep 27, 2011, at 3:22 PM, Ethan Furman wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; ">Well, actually, I'd be using it with dates. ;)</span></blockquote></div><br><div>FWIW, an approach using itertools is pretty general but even it doesn't work for dates :-)</div><div><br></div><div><div>>>> from itertools import count, takewhile</div><div>>>> from decimal import Decimal</div><div>>>> from fractions import Fraction</div><div><br></div><div>>>> list(takewhile(lambda x: x<=10.0, count(0.0, 0.5)))</div><div>[0.0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 6.0, 6.5, 7.0, 7.5, 8.0, 8.5, 9.0, 9.5, 10.0]</div><div><br></div><div>>>> list(takewhile(lambda x: x<=Decimal(1), count(Decimal(0), Decimal('0.1'))))</div><div>[Decimal('0'), Decimal('0.1'), Decimal('0.2'), Decimal('0.3'), Decimal('0.4'), Decimal('0.5'), Decimal('0.6'), Decimal('0.7'), Decimal('0.8'), Decimal('0.9'), Decimal('1.0')]</div><div><br></div><div>>>> list(takewhile(lambda x: x<=Fraction(2), count(Fraction(0), Fraction(1,3))))</div><div>[Fraction(0, 1), Fraction(1, 3), Fraction(2, 3), Fraction(1, 1), Fraction(4, 3), Fraction(5, 3), Fraction(2, 1)]</div><div><br></div></div><div><div>>>> from datetime import date, timedelta</div><div>>>> list(takewhile(lambda x: x<=date(2011,12,31), count(date(2011,9,27), timedelta(days=7))))</div><div><br></div><div>Traceback (most recent call last):</div><div> File "<pyshell#17>", line 1, in <module></div><div> list(takewhile(lambda x: x<=date(2011,12,31), count(date(2011,9,27), timedelta(days=7))))</div><div>TypeError: a number is required</div></div><div><br></div><div>Raymond</div></body></html>