<?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: Itertools</title>
	<atom:link href="http://joernhees.de/blog/2010/07/23/itertools/feed/" rel="self" type="application/rss+xml" />
	<link>http://joernhees.de/blog/2010/07/23/itertools/</link>
	<description>Science, code and links.</description>
	<lastBuildDate>Wed, 01 Feb 2012 14:54:16 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: joern</title>
		<link>http://joernhees.de/blog/2010/07/23/itertools/#comment-31</link>
		<dc:creator>joern</dc:creator>
		<pubDate>Sat, 24 Jul 2010 15:40:57 +0000</pubDate>
		<guid isPermaLink="false">http://joernhees.de/blog/?p=101#comment-31</guid>
		<description>You can also use generator expressions instead of izip:
[cc_python]
pairs = ( (i,j) for i in g for j in h )
pairs.next() # (a,1)
# ...
[/cc_python]

And [cci_python]itertools.islice()[/cci_python] comes in handy if you just need to iterate over a (large*) part of the resulting list.
* you could use [cci_python]list(it.islice(pairs, 10))[/cci_python] if it&#039;s small (here 10 first pairs).</description>
		<content:encoded><![CDATA[<p>You can also use generator expressions instead of izip:</p>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:640px;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">pairs <span style="color: #66cc66;">=</span> <span style="color: black;">&#40;</span> <span style="color: black;">&#40;</span>i<span style="color: #66cc66;">,</span>j<span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> g <span style="color: #ff7700;font-weight:bold;">for</span> j <span style="color: #ff7700;font-weight:bold;">in</span> h <span style="color: black;">&#41;</span><br />
pairs.<span style="color: black;">next</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;"># (a,1)</span><br />
<span style="color: #808080; font-style: italic;"># ...</span></div></div>
<p>And <code class="codecolorer python default"><span class="python"><span style="color: #dc143c;">itertools</span>.<span style="color: black;">islice</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></span></code> comes in handy if you just need to iterate over a (large*) part of the resulting list.<br />
* you could use <code class="codecolorer python default"><span class="python"><span style="color: #008000;">list</span><span style="color: black;">&#40;</span>it.<span style="color: black;">islice</span><span style="color: black;">&#40;</span>pairs<span style="color: #66cc66;">,</span> <span style="color: #ff4500;">10</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></span></code> if it&#8217;s small (here 10 first pairs).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Günther</title>
		<link>http://joernhees.de/blog/2010/07/23/itertools/#comment-29</link>
		<dc:creator>Günther</dc:creator>
		<pubDate>Sat, 24 Jul 2010 14:41:26 +0000</pubDate>
		<guid isPermaLink="false">http://joernhees.de/blog/?p=101#comment-29</guid>
		<description>Cool -- I recently implemented the zip() function myself, thanks for the hint! :-)</description>
		<content:encoded><![CDATA[<p>Cool &#8212; I recently implemented the zip() function myself, thanks for the hint! <img src='http://joernhees.de/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
</channel>
</rss>

