<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Inclusive range() in Python</title>
	<atom:link href="http://zeta-puppis.com/2008/03/06/inclusive-range-in-python/feed/" rel="self" type="application/rss+xml" />
	<link>http://zeta-puppis.com/2008/03/06/inclusive-range-in-python/</link>
	<description>my very own personal corner</description>
	<lastBuildDate>Sun, 29 Aug 2010 17:26:31 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Jon</title>
		<link>http://zeta-puppis.com/2008/03/06/inclusive-range-in-python/comment-page-1/#comment-3643</link>
		<dc:creator>Jon</dc:creator>
		<pubDate>Fri, 19 Jun 2009 19:16:25 +0000</pubDate>
		<guid isPermaLink="false">http://zeta-puppis.com/2008/03/06/inclusive-range-in-python/#comment-3643</guid>
		<description>I think Chris&#039;s definition is not quite right. Consider these calls:

&lt;code&gt;
range(1, 5, 3) =&gt; [1, 4]
inclusive_range(1, 5, 3) =&gt; [1, 4, 7]
&lt;/code&gt;

The inclusive range shouldn&#039;t include 7, since it is strictly greater than 5.

I think this is one way to define the interface with the same semantics as the range() built-in other than changing the right bound to be inclusive:

&lt;code&gt;
def inclusive_range(*args):
    if len(args) == 1:
        start = 0
        stop = args[0]
        step = 1
    elif len(args) == 2:
        (start, stop) = args
        step = 1
    elif len(args) == 3:
        (start, stop, step) = args
    else:
        raise TypeError(&quot;Expected 1-3 args, got&quot;, len(args))
    if step &gt; 0:
        return range(start, stop + 1, step)
    else:
        return range(start, stop - 1, step)
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>I think Chris&#8217;s definition is not quite right. Consider these&nbsp;calls:</p>
<p><code><br />
range(1, 5, 3) =&gt; [1, 4]<br />
inclusive_range(1, 5, 3) =&gt; [1, 4, 7]<br />
</code></p>
<p>The inclusive range shouldn&#8217;t include 7, since it is strictly greater than&nbsp;5.</p>
<p>I think this is one way to define the interface with the same semantics as the range() built-in other than changing the right bound to be&nbsp;inclusive:</p>
<p><code><br />
def inclusive_range(*args):<br />
    if len(args) == 1:<br />
        start = 0<br />
        stop = args[0]<br />
        step = 1<br />
    elif len(args) == 2:<br />
        (start, stop) = args<br />
        step = 1<br />
    elif len(args) == 3:<br />
        (start, stop, step) = args<br />
    else:<br />
        raise TypeError("Expected 1-3 args, got", len(args))<br />
    if step &gt; 0:<br />
        return range(start, stop + 1, step)<br />
    else:<br />
        return range(start, stop - 1, step)<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kenny Katzgrau</title>
		<link>http://zeta-puppis.com/2008/03/06/inclusive-range-in-python/comment-page-1/#comment-219</link>
		<dc:creator>Kenny Katzgrau</dc:creator>
		<pubDate>Sat, 16 Aug 2008 14:17:18 +0000</pubDate>
		<guid isPermaLink="false">http://zeta-puppis.com/2008/03/06/inclusive-range-in-python/#comment-219</guid>
		<description>@ Comments 1 &amp; 2:

Lol. That&#039;s great -- been there.</description>
		<content:encoded><![CDATA[<p>@ Comments 1 &amp;&nbsp;2:</p>
<p>Lol. That&#8217;s great&thinsp;&#8212;&thinsp;been&nbsp;there.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Wes Turner</title>
		<link>http://zeta-puppis.com/2008/03/06/inclusive-range-in-python/comment-page-1/#comment-177</link>
		<dc:creator>Wes Turner</dc:creator>
		<pubDate>Thu, 05 Jun 2008 04:54:16 +0000</pubDate>
		<guid isPermaLink="false">http://zeta-puppis.com/2008/03/06/inclusive-range-in-python/#comment-177</guid>
		<description>irange = lambda x,y,z=1: range(x,y+1,z)</description>
		<content:encoded><![CDATA[<p>irange = lambda x,y,z=1:&nbsp;range(x,y+1,z)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris Brinker</title>
		<link>http://zeta-puppis.com/2008/03/06/inclusive-range-in-python/comment-page-1/#comment-156</link>
		<dc:creator>Chris Brinker</dc:creator>
		<pubDate>Tue, 22 Apr 2008 20:21:26 +0000</pubDate>
		<guid isPermaLink="false">http://zeta-puppis.com/2008/03/06/inclusive-range-in-python/#comment-156</guid>
		<description>Dern lack of preview :)
&lt;code&gt;
def inclusive_range(start, stop, step=1):
    return(range(start, stop+step, step))
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Dern lack of preview :)<br />
<code><br />
def inclusive_range(start, stop, step=1):<br />
    return(range(start, stop+step, step))<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris Brinker</title>
		<link>http://zeta-puppis.com/2008/03/06/inclusive-range-in-python/comment-page-1/#comment-155</link>
		<dc:creator>Chris Brinker</dc:creator>
		<pubDate>Tue, 22 Apr 2008 20:20:29 +0000</pubDate>
		<guid isPermaLink="false">http://zeta-puppis.com/2008/03/06/inclusive-range-in-python/#comment-155</guid>
		<description>You may want to consider a situation with a negative step as well, in which case it is just better to add the step (positive or negative) to the stop:

def inclusive_range(start, stop, step=1):
return(range(start, stop+step, step))

-Chris</description>
		<content:encoded><![CDATA[<p>You may want to consider a situation with a negative step as well, in which case it is just better to add the step (positive or negative) to the&nbsp;stop:</p>
<p>def inclusive_range(start, stop, step=1):<br />
return(range(start, stop+step,&nbsp;step))</p>
<p>-Chris</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Giuliani Vito, Ivan</title>
		<link>http://zeta-puppis.com/2008/03/06/inclusive-range-in-python/comment-page-1/#comment-130</link>
		<dc:creator>Giuliani Vito, Ivan</dc:creator>
		<pubDate>Thu, 06 Mar 2008 22:41:51 +0000</pubDate>
		<guid isPermaLink="false">http://zeta-puppis.com/2008/03/06/inclusive-range-in-python/#comment-130</guid>
		<description>goddamn... this is what happens when coding 8 hours straight on...</description>
		<content:encoded><![CDATA[<p>goddamn&#8230; this is what happens when coding 8 hours straight&nbsp;on&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Xubuntix</title>
		<link>http://zeta-puppis.com/2008/03/06/inclusive-range-in-python/comment-page-1/#comment-129</link>
		<dc:creator>Xubuntix</dc:creator>
		<pubDate>Thu, 06 Mar 2008 22:10:58 +0000</pubDate>
		<guid isPermaLink="false">http://zeta-puppis.com/2008/03/06/inclusive-range-in-python/#comment-129</guid>
		<description>How fast is:
def inclusive_range(start, stop, step=1):
    return(range(start, stop+1, step))

?</description>
		<content:encoded><![CDATA[<p>How fast is:<br />
def inclusive_range(start, stop, step=1):<br />
    return(range(start, stop+1,&nbsp;step))</p>
<p>?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
