<?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"
	>
<channel>
	<title>Comments on: Collecting Python insights</title>
	<atom:link href="http://eli.thegreenplace.net/2008/07/03/collecting-python-insights/feed/" rel="self" type="application/rss+xml" />
	<link>http://eli.thegreenplace.net/2008/07/03/collecting-python-insights/</link>
	<description>Eli Bendersky's personal website</description>
	<pubDate>Fri, 21 Nov 2008 16:46:03 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
		<item>
		<title>By: Pablo</title>
		<link>http://eli.thegreenplace.net/2008/07/03/collecting-python-insights/#comment-124986</link>
		<dc:creator>Pablo</dc:creator>
		<pubDate>Sat, 02 Aug 2008 08:09:05 +0000</pubDate>
		<guid isPermaLink="false">http://eli.thegreenplace.net/2008/07/03/collecting-python-insights/#comment-124986</guid>
		<description>defaultdict(int) is faster than defaultdict(lambda: 0)</description>
		<content:encoded><![CDATA[<p>defaultdict(int) is faster than defaultdict(lambda: 0)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ivan</title>
		<link>http://eli.thegreenplace.net/2008/07/03/collecting-python-insights/#comment-124869</link>
		<dc:creator>Ivan</dc:creator>
		<pubDate>Thu, 31 Jul 2008 05:49:31 +0000</pubDate>
		<guid isPermaLink="false">http://eli.thegreenplace.net/2008/07/03/collecting-python-insights/#comment-124869</guid>
		<description>Function reverse won't work for UTF8 strings</description>
		<content:encoded><![CDATA[<p>Function reverse won&#8217;t work for UTF8 strings</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Screwtape</title>
		<link>http://eli.thegreenplace.net/2008/07/03/collecting-python-insights/#comment-123420</link>
		<dc:creator>Screwtape</dc:creator>
		<pubDate>Fri, 04 Jul 2008 11:45:50 +0000</pubDate>
		<guid isPermaLink="false">http://eli.thegreenplace.net/2008/07/03/collecting-python-insights/#comment-123420</guid>
		<description>The example for 'Dynamic code evaluation' is a good example of how to use exec, but a bad example of when exec is appropriate.The following code is a much nicer way of achieving the same thing, because it doesn't involve exec and hence you never have to worry about people feeding it malicious strings:


def make_packet_extract(a, b):
____def foo(packet):
________return ord(packet[a]) + 256 * ord(packet[b])
____return foo


(apologies for the underscores, &#60;pre&#62; didn't seem to want to do its thing)

A better example for exec might be something where you have to change the actual structure of the method you're building rather than just values within it - changing 'and' to 'or' or similar.</description>
		<content:encoded><![CDATA[<p>The example for &#8216;Dynamic code evaluation&#8217; is a good example of how to use exec, but a bad example of when exec is appropriate.The following code is a much nicer way of achieving the same thing, because it doesn&#8217;t involve exec and hence you never have to worry about people feeding it malicious strings:</p>
<p>def make_packet_extract(a, b):<br />
____def foo(packet):<br />
________return ord(packet[a]) + 256 * ord(packet[b])<br />
____return foo</p>
<p>(apologies for the underscores, &lt;pre&gt; didn&#8217;t seem to want to do its thing)</p>
<p>A better example for exec might be something where you have to change the actual structure of the method you&#8217;re building rather than just values within it - changing &#8216;and&#8217; to &#8216;or&#8217; or similar.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: alain</title>
		<link>http://eli.thegreenplace.net/2008/07/03/collecting-python-insights/#comment-123413</link>
		<dc:creator>alain</dc:creator>
		<pubDate>Fri, 04 Jul 2008 06:35:48 +0000</pubDate>
		<guid isPermaLink="false">http://eli.thegreenplace.net/2008/07/03/collecting-python-insights/#comment-123413</guid>
		<description>Python doesn't have a reverse builtin but it has a reversed builtin:
for char in reversed("hello world"):
   print char</description>
		<content:encoded><![CDATA[<p>Python doesn&#8217;t have a reverse builtin but it has a reversed builtin:<br />
for char in reversed(&#8221;hello world&#8221;):<br />
   print char</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: eliben</title>
		<link>http://eli.thegreenplace.net/2008/07/03/collecting-python-insights/#comment-123411</link>
		<dc:creator>eliben</dc:creator>
		<pubDate>Fri, 04 Jul 2008 05:21:47 +0000</pubDate>
		<guid isPermaLink="false">http://eli.thegreenplace.net/2008/07/03/collecting-python-insights/#comment-123411</guid>
		<description>Mahadevan R:

The "insights" supposes RandomChunk already exists and can't be modified.</description>
		<content:encoded><![CDATA[<p>Mahadevan R:</p>
<p>The &#8220;insights&#8221; supposes RandomChunk already exists and can&#8217;t be modified.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: eliben</title>
		<link>http://eli.thegreenplace.net/2008/07/03/collecting-python-insights/#comment-123410</link>
		<dc:creator>eliben</dc:creator>
		<pubDate>Fri, 04 Jul 2008 05:21:17 +0000</pubDate>
		<guid isPermaLink="false">http://eli.thegreenplace.net/2008/07/03/collecting-python-insights/#comment-123410</guid>
		<description>JB:

As this benchmark demonstrates, you are quite wrong. xrange is faster (tried for both large and small LISTSIZE):

&lt;prE lang="python"&gt;
import timeit


setup = """
LISTSIZE = 10
"""

s1 = """
k = 0
for i in range(LISTSIZE): k += i
"""

s2 = """
k = 0
for i in xrange(LISTSIZE): k += i
"""


N = 50000
print "range on integer", timeit.Timer(stmt=s1, setup=setup).timeit(N)
print "xrange on integer", timeit.Timer(stmt=s2, setup=setup).timeit(N)
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>JB:</p>
<p>As this benchmark demonstrates, you are quite wrong. xrange is faster (tried for both large and small LISTSIZE):</p>
<pre lang="python">
import timeit

setup = &#8220;&#8221;"
LISTSIZE = 10
&#8220;&#8221;"

s1 = &#8220;&#8221;"
k = 0
for i in range(LISTSIZE): k += i
&#8220;&#8221;"

s2 = &#8220;&#8221;"
k = 0
for i in xrange(LISTSIZE): k += i
&#8220;&#8221;"

N = 50000
print &#8220;range on integer&#8221;, timeit.Timer(stmt=s1, setup=setup).timeit(N)
print &#8220;xrange on integer&#8221;, timeit.Timer(stmt=s2, setup=setup).timeit(N)
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mahadevan R</title>
		<link>http://eli.thegreenplace.net/2008/07/03/collecting-python-insights/#comment-123407</link>
		<dc:creator>Mahadevan R</dc:creator>
		<pubDate>Fri, 04 Jul 2008 04:40:17 +0000</pubDate>
		<guid isPermaLink="false">http://eli.thegreenplace.net/2008/07/03/collecting-python-insights/#comment-123407</guid>
		<description>In RandomChunker.chunk(), instead of "return ret", do "yield ret". Then, you can:

for chunk in rc.chunk():
    print chunk

Cheers,
-Mahadevan.</description>
		<content:encoded><![CDATA[<p>In RandomChunker.chunk(), instead of &#8220;return ret&#8221;, do &#8220;yield ret&#8221;. Then, you can:</p>
<p>for chunk in rc.chunk():<br />
    print chunk</p>
<p>Cheers,<br />
-Mahadevan.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: JB</title>
		<link>http://eli.thegreenplace.net/2008/07/03/collecting-python-insights/#comment-123384</link>
		<dc:creator>JB</dc:creator>
		<pubDate>Thu, 03 Jul 2008 18:05:34 +0000</pubDate>
		<guid isPermaLink="false">http://eli.thegreenplace.net/2008/07/03/collecting-python-insights/#comment-123384</guid>
		<description>xrange uses less memory, but it is slightly slower, as it needs to generate each value on demand.

Just sayin'.</description>
		<content:encoded><![CDATA[<p>xrange uses less memory, but it is slightly slower, as it needs to generate each value on demand.</p>
<p>Just sayin&#8217;.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
