<?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: Sort one list by another list</title>
	<atom:link href="http://scienceoss.com/sort-one-list-by-another-list/feed/" rel="self" type="application/rss+xml" />
	<link>http://scienceoss.com/sort-one-list-by-another-list/</link>
	<description>useful tidbits for using open source software in science</description>
	<lastBuildDate>Thu, 19 Jan 2012 02:43:36 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: ryan</title>
		<link>http://scienceoss.com/sort-one-list-by-another-list/comment-page-1/#comment-34</link>
		<dc:creator>ryan</dc:creator>
		<pubDate>Mon, 14 Apr 2008 20:22:03 +0000</pubDate>
		<guid isPermaLink="false">http://scienceoss.com/sort-one-list-by-another-list/#comment-34</guid>
		<description>Inspired by Andrew I learned some more about using a key function to sort by. My notes are here: http://scienceoss.com/advanced-sorting-sorting-by-key/</description>
		<content:encoded><![CDATA[<p>Inspired by Andrew I learned some more about using a key function to sort by. My notes are here: <a href="http://scienceoss.com/advanced-sorting-sorting-by-key/" rel="nofollow">http://scienceoss.com/advanced-sorting-sorting-by-key/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ryan</title>
		<link>http://scienceoss.com/sort-one-list-by-another-list/comment-page-1/#comment-27</link>
		<dc:creator>ryan</dc:creator>
		<pubDate>Sun, 13 Apr 2008 17:03:06 +0000</pubDate>
		<guid isPermaLink="false">http://scienceoss.com/sort-one-list-by-another-list/#comment-27</guid>
		<description>@Matt:
You got me thinking about whether or not the first way is best.  Turns out sometimes the first method is best . . . but sometimes it&#039;s not.  For more:  http://scienceoss.com/test-the-speed-of-your-code-interactively-in-ipython/.

@Andrew Perry:
Good call on using the key function to sort by.  Now that I think about it, it might be worth a separate post with some more examples of using &quot;sort(key=someFunc)&quot;.  Stay tuned.</description>
		<content:encoded><![CDATA[<p>@Matt:<br />
You got me thinking about whether or not the first way is best.  Turns out sometimes the first method is best . . . but sometimes it&#8217;s not.  For more:  <a href="http://scienceoss.com/test-the-speed-of-your-code-interactively-in-ipython/" rel="nofollow">http://scienceoss.com/test-the-speed-of-your-code-interactively-in-ipython/</a>.</p>
<p>@Andrew Perry:<br />
Good call on using the key function to sort by.  Now that I think about it, it might be worth a separate post with some more examples of using &#8220;sort(key=someFunc)&#8221;.  Stay tuned.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrew Perry</title>
		<link>http://scienceoss.com/sort-one-list-by-another-list/comment-page-1/#comment-25</link>
		<dc:creator>Andrew Perry</dc:creator>
		<pubDate>Sun, 13 Apr 2008 01:49:59 +0000</pubDate>
		<guid isPermaLink="false">http://scienceoss.com/sort-one-list-by-another-list/#comment-25</guid>
		<description>Thanks, nice quick tutorial. I&#039;ve really got to use Numpy more often, I&#039;m sure it would make my life easier.

Just playing with the examples ... here&#039;s how to sort the list alphabetically by &quot;people&quot; rather than by age (for Method 1). Change the .sort() line to:

agesAndPeople.sort(key=lambda x: x[1])

The key argument can be passed any function which when passed any element of the list being sorted, returns a value to actually sort on. In this case, the key function is a quick on-the-fly lamba function which returns the second element of the tuple (rather than defaulting to the first element, as in Method 1 above), in effect sorting on the peoples names rather than the age.</description>
		<content:encoded><![CDATA[<p>Thanks, nice quick tutorial. I&#8217;ve really got to use Numpy more often, I&#8217;m sure it would make my life easier.</p>
<p>Just playing with the examples &#8230; here&#8217;s how to sort the list alphabetically by &#8220;people&#8221; rather than by age (for Method 1). Change the .sort() line to:</p>
<p>agesAndPeople.sort(key=lambda x: x[1])</p>
<p>The key argument can be passed any function which when passed any element of the list being sorted, returns a value to actually sort on. In this case, the key function is a quick on-the-fly lamba function which returns the second element of the tuple (rather than defaulting to the first element, as in Method 1 above), in effect sorting on the peoples names rather than the age.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt</title>
		<link>http://scienceoss.com/sort-one-list-by-another-list/comment-page-1/#comment-18</link>
		<dc:creator>Matt</dc:creator>
		<pubDate>Fri, 11 Apr 2008 21:42:11 +0000</pubDate>
		<guid isPermaLink="false">http://scienceoss.com/sort-one-list-by-another-list/#comment-18</guid>
		<description>How isn&#039;t the first way the best?</description>
		<content:encoded><![CDATA[<p>How isn&#8217;t the first way the best?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

