<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Sorting Dictionaries by Value in Python (improved?)</title>
	<atom:link href="http://writeonly.wordpress.com/2008/08/30/sorting-dictionaries-by-value-in-python-improved/feed/" rel="self" type="application/rss+xml" />
	<link>http://writeonly.wordpress.com/2008/08/30/sorting-dictionaries-by-value-in-python-improved/</link>
	<description>Programming, numbers, and other kinks</description>
	<lastBuildDate>Tue, 10 Nov 2009 15:09:29 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Daniel Drucker</title>
		<link>http://writeonly.wordpress.com/2008/08/30/sorting-dictionaries-by-value-in-python-improved/#comment-345</link>
		<dc:creator>Daniel Drucker</dc:creator>
		<pubDate>Tue, 10 Nov 2009 15:09:29 +0000</pubDate>
		<guid isPermaLink="false">http://writeonly.wordpress.com/?p=7#comment-345</guid>
		<description>There&#039;s an error in sbv6; you say &#039;reverse=True&#039; instead of &#039;reverse=reverse&#039;.</description>
		<content:encoded><![CDATA[<p>There&#8217;s an error in sbv6; you say &#8216;reverse=True&#8217; instead of &#8216;reverse=reverse&#8217;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gregg Lind</title>
		<link>http://writeonly.wordpress.com/2008/08/30/sorting-dictionaries-by-value-in-python-improved/#comment-207</link>
		<dc:creator>Gregg Lind</dc:creator>
		<pubDate>Tue, 30 Jun 2009 14:14:01 +0000</pubDate>
		<guid isPermaLink="false">http://writeonly.wordpress.com/?p=7#comment-207</guid>
		<description>@Andy,

Python 3.1 ordered dictionaries won&#039;t fix this problem unfortunately.  All ordered dictionaries do is ensure that the dictionary always iterates in the same way, based on *insertion order*.</description>
		<content:encoded><![CDATA[<p>@Andy,</p>
<p>Python 3.1 ordered dictionaries won&#8217;t fix this problem unfortunately.  All ordered dictionaries do is ensure that the dictionary always iterates in the same way, based on *insertion order*.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andy</title>
		<link>http://writeonly.wordpress.com/2008/08/30/sorting-dictionaries-by-value-in-python-improved/#comment-206</link>
		<dc:creator>Andy</dc:creator>
		<pubDate>Tue, 30 Jun 2009 05:59:06 +0000</pubDate>
		<guid isPermaLink="false">http://writeonly.wordpress.com/?p=7#comment-206</guid>
		<description>In a few years this will be just a little easier for everyone :)

Ordered dictionaries in 3.1:
http://docs.python.org/dev/py3k/whatsnew/3.1.html</description>
		<content:encoded><![CDATA[<p>In a few years this will be just a little easier for everyone <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Ordered dictionaries in 3.1:<br />
<a href="http://docs.python.org/dev/py3k/whatsnew/3.1.html" rel="nofollow">http://docs.python.org/dev/py3k/whatsnew/3.1.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gregg Lind</title>
		<link>http://writeonly.wordpress.com/2008/08/30/sorting-dictionaries-by-value-in-python-improved/#comment-178</link>
		<dc:creator>Gregg Lind</dc:creator>
		<pubDate>Mon, 08 Jun 2009 13:40:03 +0000</pubDate>
		<guid isPermaLink="false">http://writeonly.wordpress.com/?p=7#comment-178</guid>
		<description>This is maybe non-obvious, but if you convert it back to a dictionary, then you lose the ordering!  That&#039;s the whole point of sorting, it to end up with something sorted.  Think about it a bit :)

To use:

for (k,v) in sbv6(my_dict):   do_function(k,v) # example</description>
		<content:encoded><![CDATA[<p>This is maybe non-obvious, but if you convert it back to a dictionary, then you lose the ordering!  That&#8217;s the whole point of sorting, it to end up with something sorted.  Think about it a bit <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>To use:</p>
<p>for (k,v) in sbv6(my_dict):   do_function(k,v) # example</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andy</title>
		<link>http://writeonly.wordpress.com/2008/08/30/sorting-dictionaries-by-value-in-python-improved/#comment-177</link>
		<dc:creator>Andy</dc:creator>
		<pubDate>Mon, 08 Jun 2009 13:32:04 +0000</pubDate>
		<guid isPermaLink="false">http://writeonly.wordpress.com/?p=7#comment-177</guid>
		<description>&gt;&gt; It has to be list (or it wouldn’t be orderable), and the tuple makes sense since the data in each position has a meaning (KEY, X).


In that case, i think i will have to just use the list.

I already tried to convert it back to a dict, but that caused me to end up with my original input. 

Thanks for your answer.</description>
		<content:encoded><![CDATA[<p>&gt;&gt; It has to be list (or it wouldn’t be orderable), and the tuple makes sense since the data in each position has a meaning (KEY, X).</p>
<p>In that case, i think i will have to just use the list.</p>
<p>I already tried to convert it back to a dict, but that caused me to end up with my original input. </p>
<p>Thanks for your answer.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andy</title>
		<link>http://writeonly.wordpress.com/2008/08/30/sorting-dictionaries-by-value-in-python-improved/#comment-176</link>
		<dc:creator>Andy</dc:creator>
		<pubDate>Mon, 08 Jun 2009 13:29:16 +0000</pubDate>
		<guid isPermaLink="false">http://writeonly.wordpress.com/?p=7#comment-176</guid>
		<description>I seem to have hit submit too quick. 
The input was 

{&#039;127.0.0.1&#039;: [&#039;yes&#039;, &#039;9999&#039;], &#039;remote_host&#039;: [&#039;no&#039;, &#039;8888&#039;], &#039;localhost&#039;: [&#039;yes&#039;, &#039;9999&#039;]}

and the output is 

[(&#039;remote_host&#039;, [&#039;no&#039;, &#039;8888&#039;]), (&#039;127.0.0.1&#039;, [&#039;yes&#039;, &#039;9999&#039;]), (&#039;localhost&#039;, [&#039;yes&#039;, &#039;9999&#039;])]</description>
		<content:encoded><![CDATA[<p>I seem to have hit submit too quick.<br />
The input was </p>
<p>{&#8216;127.0.0.1&#8242;: ['yes', '9999'], &#8216;remote_host&#8217;: ['no', '8888'], &#8216;localhost&#8217;: ['yes', '9999']}</p>
<p>and the output is </p>
<p>[('remote_host', ['no', '8888']), (&#8216;127.0.0.1&#8242;, ['yes', '9999']), (&#8216;localhost&#8217;, ['yes', '9999'])]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gregg Lind</title>
		<link>http://writeonly.wordpress.com/2008/08/30/sorting-dictionaries-by-value-in-python-improved/#comment-175</link>
		<dc:creator>Gregg Lind</dc:creator>
		<pubDate>Mon, 08 Jun 2009 13:24:53 +0000</pubDate>
		<guid isPermaLink="false">http://writeonly.wordpress.com/?p=7#comment-175</guid>
		<description>So, in your example, you have a dict of lists, or a dict of &quot;X&quot;s.  The general pattern for what you get back is:

_LIST_ of _TUPLES_, where each TUPLE has 2 elements:  (KEY, X).  

It has to be list (or it wouldn&#039;t be orderable), and the tuple makes sense since the data in each position has a meaning (KEY, X).  

I&#039;m glad you found this helpful!</description>
		<content:encoded><![CDATA[<p>So, in your example, you have a dict of lists, or a dict of &#8220;X&#8221;s.  The general pattern for what you get back is:</p>
<p>_LIST_ of _TUPLES_, where each TUPLE has 2 elements:  (KEY, X).  </p>
<p>It has to be list (or it wouldn&#8217;t be orderable), and the tuple makes sense since the data in each position has a meaning (KEY, X).  </p>
<p>I&#8217;m glad you found this helpful!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andy</title>
		<link>http://writeonly.wordpress.com/2008/08/30/sorting-dictionaries-by-value-in-python-improved/#comment-174</link>
		<dc:creator>Andy</dc:creator>
		<pubDate>Mon, 08 Jun 2009 13:18:12 +0000</pubDate>
		<guid isPermaLink="false">http://writeonly.wordpress.com/?p=7#comment-174</guid>
		<description>Great post. I ran into the same requirement and sv6 seems to address it really well. 

Yet, as also mentioned in PEP 265, this is not really an approach obvious to newbies. Can you give me -and doubtlessly some other newbies- an example of how to get the output back in the dict structure which was passed to sv6? 

Here is an example. Having passed the following data:

{&#039;127.0.0.1&#039;: [&#039;no&#039;, &#039;9999&#039;], &#039;remote_host&#039;: [&#039;no&#039;, &#039;888&#039;], &#039;localhost&#039;: [&#039;yes&#039;, &#039;9999&#039;]}

i get this back 

[(&#039;localhost&#039;, [&#039;yes&#039;, &#039;9999&#039;]), (&#039;remote_host&#039;, [&#039;no&#039;, &#039;8888&#039;]), (&#039;127.0.0.1&#039;, [&#039;no&#039;, &#039;9999&#039;])]

From what i have learned so far, it looks like a list with tuples and lists inside those tuples.

Thanks in advance.</description>
		<content:encoded><![CDATA[<p>Great post. I ran into the same requirement and sv6 seems to address it really well. </p>
<p>Yet, as also mentioned in PEP 265, this is not really an approach obvious to newbies. Can you give me -and doubtlessly some other newbies- an example of how to get the output back in the dict structure which was passed to sv6? </p>
<p>Here is an example. Having passed the following data:</p>
<p>{&#8216;127.0.0.1&#8242;: ['no', '9999'], &#8216;remote_host&#8217;: ['no', '888'], &#8216;localhost&#8217;: ['yes', '9999']}</p>
<p>i get this back </p>
<p>[('localhost', ['yes', '9999']), (&#8216;remote_host&#8217;, ['no', '8888']), (&#8216;127.0.0.1&#8242;, ['no', '9999'])]</p>
<p>From what i have learned so far, it looks like a list with tuples and lists inside those tuples.</p>
<p>Thanks in advance.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: digital sanitation engineering: Sorting Python Dictionary By Value &#171; 藏袍逢毅</title>
		<link>http://writeonly.wordpress.com/2008/08/30/sorting-dictionaries-by-value-in-python-improved/#comment-114</link>
		<dc:creator>digital sanitation engineering: Sorting Python Dictionary By Value &#171; 藏袍逢毅</dc:creator>
		<pubDate>Thu, 09 Apr 2009 04:55:08 +0000</pubDate>
		<guid isPermaLink="false">http://writeonly.wordpress.com/?p=7#comment-114</guid>
		<description>[...] Gregg Lind (aka &#8220;write-only&#8221;) replied to the article with a comment pointing to his performance notes. PEP 0265 has the &#8220;best answer&#8221; that is at least 2x [...]</description>
		<content:encoded><![CDATA[<p>[...] Gregg Lind (aka &#8220;write-only&#8221;) replied to the article with a comment pointing to his performance notes. PEP 0265 has the &#8220;best answer&#8221; that is at least 2x [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: writeonly</title>
		<link>http://writeonly.wordpress.com/2008/08/30/sorting-dictionaries-by-value-in-python-improved/#comment-54</link>
		<dc:creator>writeonly</dc:creator>
		<pubDate>Fri, 12 Dec 2008 00:13:33 +0000</pubDate>
		<guid isPermaLink="false">http://writeonly.wordpress.com/?p=7#comment-54</guid>
		<description>Paul, thanks for the tips.  Looking through the code for nlargest, there&#039;s a lot more going on there.  Maybe this would be a good place to do a patch :)


_nlargest = nlargest
def nlargest(n, iterable, key=None):
    &quot;&quot;&quot;Find the n largest elements in a dataset.

    Equivalent to:  sorted(iterable, key=key, reverse=True)[:n]
    &quot;&quot;&quot;
    in1, in2 = tee(iterable)
    keys = in1 if key is None else map(key, in1)
    it = zip(keys, map(neg, count()), in2)                 # decorate
    result = _nlargest(n, it)
    return list(map(itemgetter(2), result))                 # undecorate</description>
		<content:encoded><![CDATA[<p>Paul, thanks for the tips.  Looking through the code for nlargest, there&#8217;s a lot more going on there.  Maybe this would be a good place to do a patch <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>_nlargest = nlargest<br />
def nlargest(n, iterable, key=None):<br />
    &#8220;&#8221;"Find the n largest elements in a dataset.</p>
<p>    Equivalent to:  sorted(iterable, key=key, reverse=True)[:n]<br />
    &#8220;&#8221;"<br />
    in1, in2 = tee(iterable)<br />
    keys = in1 if key is None else map(key, in1)<br />
    it = zip(keys, map(neg, count()), in2)                 # decorate<br />
    result = _nlargest(n, it)<br />
    return list(map(itemgetter(2), result))                 # undecorate</p>
]]></content:encoded>
	</item>
</channel>
</rss>
