<?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: Python 3.1, you shouldn&#8217;t have!</title>
	<atom:link href="http://blog.cdleary.com/2009/07/python-3-1-you-shouldnt-have/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.cdleary.com/2009/07/python-3-1-you-shouldnt-have/</link>
	<description>__author__ = &#039;Chris Leary&#039;</description>
	<lastBuildDate>Mon, 06 Sep 2010 19:31:04 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: Malthe</title>
		<link>http://blog.cdleary.com/2009/07/python-3-1-you-shouldnt-have/comment-page-1/#comment-1148</link>
		<dc:creator>Malthe</dc:creator>
		<pubDate>Thu, 02 Jul 2009 11:21:03 +0000</pubDate>
		<guid isPermaLink="false">http://blog.cdleary.com/?p=591#comment-1148</guid>
		<description>I agree; either one of them. Certainly ``itemgetter`` is more efficient, too.</description>
		<content:encoded><![CDATA[<p>I agree; either one of them. Certainly &#8220;itemgetter&#8220; is more efficient, too.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Christopher Leary</title>
		<link>http://blog.cdleary.com/2009/07/python-3-1-you-shouldnt-have/comment-page-1/#comment-1147</link>
		<dc:creator>Christopher Leary</dc:creator>
		<pubDate>Thu, 02 Jul 2009 11:14:47 +0000</pubDate>
		<guid isPermaLink="false">http://blog.cdleary.com/?p=591#comment-1147</guid>
		<description>@Malthe: I think it has distilled down to a difference of opinion. As I see it, &lt;tt&gt;frequency_key&lt;/tt&gt; is a meaningless function outside of the context where you have a sequence with the second element being a frequency value. I personally find that function more objectionable because its name implies some sort of generality, whereas the anonymous function is intentionally throw-away in the (temporary) item-iteration context.

Overall, I&#039;m partial to an inline ``itemgetter(1)``, as mentioned by @xtian -- less ugly than a lambda, plus stdlib-approved and -documented.</description>
		<content:encoded><![CDATA[<p>@Malthe: I think it has distilled down to a difference of opinion. As I see it, <tt>frequency_key</tt> is a meaningless function outside of the context where you have a sequence with the second element being a frequency value. I personally find that function more objectionable because its name implies some sort of generality, whereas the anonymous function is intentionally throw-away in the (temporary) item-iteration context.</p>
<p>Overall, I&#8217;m partial to an inline &#8220;itemgetter(1)&#8220;, as mentioned by @xtian &#8212; less ugly than a lambda, plus stdlib-approved and -documented.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Malthe</title>
		<link>http://blog.cdleary.com/2009/07/python-3-1-you-shouldnt-have/comment-page-1/#comment-1146</link>
		<dc:creator>Malthe</dc:creator>
		<pubDate>Thu, 02 Jul 2009 10:01:39 +0000</pubDate>
		<guid isPermaLink="false">http://blog.cdleary.com/?p=591#comment-1146</guid>
		<description>Lennart&#039;s version is much more readable, which is entirely what counts.</description>
		<content:encoded><![CDATA[<p>Lennart&#8217;s version is much more readable, which is entirely what counts.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: xtian</title>
		<link>http://blog.cdleary.com/2009/07/python-3-1-you-shouldnt-have/comment-page-1/#comment-1145</link>
		<dc:creator>xtian</dc:creator>
		<pubDate>Thu, 02 Jul 2009 07:27:51 +0000</pubDate>
		<guid isPermaLink="false">http://blog.cdleary.com/?p=591#comment-1145</guid>
		<description>itemgetter(1) is much nicer than lambda t: t[1] (it lives in the operator module).</description>
		<content:encoded><![CDATA[<p>itemgetter(1) is much nicer than lambda t: t[1] (it lives in the operator module).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Christopher Leary</title>
		<link>http://blog.cdleary.com/2009/07/python-3-1-you-shouldnt-have/comment-page-1/#comment-1144</link>
		<dc:creator>Christopher Leary</dc:creator>
		<pubDate>Thu, 02 Jul 2009 04:35:08 +0000</pubDate>
		<guid isPermaLink="false">http://blog.cdleary.com/?p=591#comment-1144</guid>
		<description>@Lennart: I&#039;m willing to accept that the dict comprehension may be better written as a for loop (due to stdin side effects), but I don&#039;t agree with the elimination of the lambda. Really simple one-statement operations (like sequence indexing in a throw-away sort invocation) are the few cases where I&#039;ll actually prefer an anonymous function -- I&#039;m pretty sure that&#039;s the use case that caused lambdas to remain in the language in the transition to Py3k.

@Roberto @rgz: You guys are totally right. Been writing too much 2.x compatible code lately. ;-) Updated to reflect your correction!</description>
		<content:encoded><![CDATA[<p>@Lennart: I&#8217;m willing to accept that the dict comprehension may be better written as a for loop (due to stdin side effects), but I don&#8217;t agree with the elimination of the lambda. Really simple one-statement operations (like sequence indexing in a throw-away sort invocation) are the few cases where I&#8217;ll actually prefer an anonymous function &#8212; I&#8217;m pretty sure that&#8217;s the use case that caused lambdas to remain in the language in the transition to Py3k.</p>
<p>@Roberto @rgz: You guys are totally right. Been writing too much 2.x compatible code lately. ;-) Updated to reflect your correction!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rgz</title>
		<link>http://blog.cdleary.com/2009/07/python-3-1-you-shouldnt-have/comment-page-1/#comment-1143</link>
		<dc:creator>rgz</dc:creator>
		<pubDate>Thu, 02 Jul 2009 01:05:42 +0000</pubDate>
		<guid isPermaLink="false">http://blog.cdleary.com/?p=591#comment-1143</guid>
		<description>Instead of 

&lt;pre lang=&#039;python&#039;&gt;
    birthday = dict((part, int(input(&#039;Enter birth {}: &#039;.format(part))))
        for part in &#039;year mbirthday = dict((part, int(input(&#039;Enter birth {}: &#039;.format(part))))
        for part in &#039;year month day&#039;.split())
    onth day&#039;.split())
&lt;/pre&gt;
what about
&lt;pre lang=&#039;python&#039;&gt;
    birthday = {part: int(input(&#039;Enter birth {}: &#039;.format(part)))
        for part in &#039;year mbirthday = dict((part, int(input(&#039;Enter birth {}: &#039;.format(part))))
        for part in &#039;year month day&#039;.split())
    onth day&#039;.split()}
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Instead of</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">    birthday = <span style="color: #008000;">dict</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>part, <span style="color: #008000;">int</span><span style="color: black;">&#40;</span><span style="color: #008000;">input</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'Enter birth {}: '</span>.<span style="color: black;">format</span><span style="color: black;">&#40;</span>part<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">for</span> part <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #483d8b;">'year mbirthday = dict((part, int(input('</span>Enter birth <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span>: <span style="color: #483d8b;">'.format(part))))
        for part in '</span>year month day<span style="color: #483d8b;">'.split())
    onth day'</span>.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>what about</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">    birthday = <span style="color: black;">&#123;</span>part: <span style="color: #008000;">int</span><span style="color: black;">&#40;</span><span style="color: #008000;">input</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'Enter birth {}: '</span>.<span style="color: black;">format</span><span style="color: black;">&#40;</span>part<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">for</span> part <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #483d8b;">'year mbirthday = dict((part, int(input('</span>Enter birth <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span>: <span style="color: #483d8b;">'.format(part))))
        for part in '</span>year month day<span style="color: #483d8b;">'.split())
    onth day'</span>.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#125;</span></pre></div></div>

]]></content:encoded>
	</item>
	<item>
		<title>By: Roberto Bonvallet</title>
		<link>http://blog.cdleary.com/2009/07/python-3-1-you-shouldnt-have/comment-page-1/#comment-1142</link>
		<dc:creator>Roberto Bonvallet</dc:creator>
		<pubDate>Thu, 02 Jul 2009 00:07:50 +0000</pubDate>
		<guid isPermaLink="false">http://blog.cdleary.com/?p=591#comment-1142</guid>
		<description>You&#039;re missing dict comprehensions :)

&lt;pre lang=&#039;python&#039;&gt;
birthday = {part: int(input(&#039;Enter birth {}: &#039;.format(part)))
    for part in &#039;year month day&#039;.split()}
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>You&#8217;re missing dict comprehensions :)</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">birthday = <span style="color: black;">&#123;</span>part: <span style="color: #008000;">int</span><span style="color: black;">&#40;</span><span style="color: #008000;">input</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'Enter birth {}: '</span>.<span style="color: black;">format</span><span style="color: black;">&#40;</span>part<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">for</span> part <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #483d8b;">'year month day'</span>.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#125;</span></pre></div></div>

]]></content:encoded>
	</item>
	<item>
		<title>By: Lennart Regebro</title>
		<link>http://blog.cdleary.com/2009/07/python-3-1-you-shouldnt-have/comment-page-1/#comment-1141</link>
		<dc:creator>Lennart Regebro</dc:creator>
		<pubDate>Wed, 01 Jul 2009 21:54:16 +0000</pubDate>
		<guid isPermaLink="false">http://blog.cdleary.com/?p=591#comment-1141</guid>
		<description>Ough, the obfuscation! It hurtz!

There, I fixed it.  ;-)

&lt;pre lang=&#039;python&#039;&gt;
#!/usr/bin/env python3.1
 
import collections
import datetime
 
 
birthday = {}
for part in (&#039;year&#039;, &#039;month&#039;, &#039;day&#039;):
    birthday[part] = int(input(&#039;Enter birth {}: &#039;.format(part)))

now = datetime.datetime.now()
days = []
for year in range(birthday[&#039;year&#039;], now.year + 1):
    date = datetime.date(year, birthday[&#039;month&#039;], birthday[&#039;day&#039;])
    days.append(date.strftime(&#039;%A&#039;))
 
def frequency_key(t):
    return t[1]

counter = collections.Counter(days)
fmt = &#039;{:15} {:&gt;3}&#039;
for day, frequency in sorted(counter.items(), key=frequency_key, reverse=True):
    print(fmt.format(day, frequency))
print(fmt.format(&#039;Total&#039;, sum(counter.values())))
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Ough, the obfuscation! It hurtz!</p>
<p>There, I fixed it.  ;-)</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/env python3.1</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">collections</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">datetime</span>
&nbsp;
&nbsp;
birthday = <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span>
<span style="color: #ff7700;font-weight:bold;">for</span> part <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: black;">&#40;</span><span style="color: #483d8b;">'year'</span>, <span style="color: #483d8b;">'month'</span>, <span style="color: #483d8b;">'day'</span><span style="color: black;">&#41;</span>:
    birthday<span style="color: black;">&#91;</span>part<span style="color: black;">&#93;</span> = <span style="color: #008000;">int</span><span style="color: black;">&#40;</span><span style="color: #008000;">input</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'Enter birth {}: '</span>.<span style="color: black;">format</span><span style="color: black;">&#40;</span>part<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
now = <span style="color: #dc143c;">datetime</span>.<span style="color: #dc143c;">datetime</span>.<span style="color: black;">now</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
days = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
<span style="color: #ff7700;font-weight:bold;">for</span> year <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span>birthday<span style="color: black;">&#91;</span><span style="color: #483d8b;">'year'</span><span style="color: black;">&#93;</span>, now.<span style="color: black;">year</span> + <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>:
    date = <span style="color: #dc143c;">datetime</span>.<span style="color: black;">date</span><span style="color: black;">&#40;</span>year, birthday<span style="color: black;">&#91;</span><span style="color: #483d8b;">'month'</span><span style="color: black;">&#93;</span>, birthday<span style="color: black;">&#91;</span><span style="color: #483d8b;">'day'</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
    days.<span style="color: black;">append</span><span style="color: black;">&#40;</span>date.<span style="color: black;">strftime</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'%A'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> frequency_key<span style="color: black;">&#40;</span>t<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">return</span> t<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
&nbsp;
counter = <span style="color: #dc143c;">collections</span>.<span style="color: black;">Counter</span><span style="color: black;">&#40;</span>days<span style="color: black;">&#41;</span>
fmt = <span style="color: #483d8b;">'{:15} {:&gt;3}'</span>
<span style="color: #ff7700;font-weight:bold;">for</span> day, frequency <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">sorted</span><span style="color: black;">&#40;</span>counter.<span style="color: black;">items</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>, key=frequency_key, reverse=<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span>fmt.<span style="color: black;">format</span><span style="color: black;">&#40;</span>day, frequency<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span>fmt.<span style="color: black;">format</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'Total'</span>, <span style="color: #008000;">sum</span><span style="color: black;">&#40;</span>counter.<span style="color: black;">values</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></pre></div></div>

]]></content:encoded>
	</item>
</channel>
</rss>
