<?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: Finding the longest common prefix of an array of strings in Python, part 2</title>
	<atom:link href="http://boredzo.org/blog/archives/2007-01-06/longest-common-prefix-in-python-2/feed" rel="self" type="application/rss+xml" />
	<link>http://boredzo.org/blog/archives/2007-01-06/longest-common-prefix-in-python-2</link>
	<description>The personal weblog of Peter Hosey.</description>
	<pubDate>Thu, 20 Nov 2008 09:38:18 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<item>
		<title>By: Peter Hosey</title>
		<link>http://boredzo.org/blog/archives/2007-01-06/longest-common-prefix-in-python-2#comment-224332</link>
		<dc:creator>Peter Hosey</dc:creator>
		<pubDate>Thu, 11 Sep 2008 18:07:59 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/archives/2007-01-06/longest-common-prefix-in-python-2#comment-224332</guid>
		<description>Lars: You're absolutely right. It did, indeed, return &lt;code&gt;''&lt;/code&gt; in cases where that's wrong. (Example: &lt;code&gt;['foo', 'foobarbaz', 'foobarqux']&lt;/code&gt; should return &lt;code&gt;'foo'&lt;/code&gt;.)

Thanks.</description>
		<content:encoded><![CDATA[<p>Lars: You're absolutely right. It did, indeed, return <code>''</code> in cases where that's wrong. (Example: <code>['foo', 'foobarbaz', 'foobarqux']</code> should return <code>'foo'</code>.)</p>
<p>Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lars</title>
		<link>http://boredzo.org/blog/archives/2007-01-06/longest-common-prefix-in-python-2#comment-224325</link>
		<dc:creator>Lars</dc:creator>
		<pubDate>Thu, 11 Sep 2008 14:48:03 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/archives/2007-01-06/longest-common-prefix-in-python-2#comment-224325</guid>
		<description>You wrote:
&lt;blockquote&gt;&#62;     return ''

 If we've run out of loop, there must not be a common prefix; our common prefix, therefore, is the empty string. We return that as a literal.
&lt;/blockquote&gt;

Huh?
I don't understand this...
It seems to me that if you run out of loop, then all the characters of all the non-shortest strings have agreed with those of the shortest string.
So your common prefix is the shortest string, files[0].

It seems unlikely that I would have noticed this while you and your other readers did not... but I can't figure out why the way it's written would be correct.
If you answer this, I'd appreciate an email. I don't normally check this blog.</description>
		<content:encoded><![CDATA[<p>You wrote:</p>
<blockquote cite="http://boredzo.org/blog/archives/2007-01-06/longest-common-prefix-in-python-2#comment-"><p>&gt;     return ''</p>
<p> If we've run out of loop, there must not be a common prefix; our common prefix, therefore, is the empty string. We return that as a literal.
</p>
</blockquote>
<p>Huh?<br />
I don't understand this...<br />
It seems to me that if you run out of loop, then all the characters of all the non-shortest strings have agreed with those of the shortest string.<br />
So your common prefix is the shortest string, files[0].</p>
<p>It seems unlikely that I would have noticed this while you and your other readers did not... but I can't figure out why the way it's written would be correct.<br />
If you answer this, I'd appreciate an email. I don't normally check this blog.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter Hosey</title>
		<link>http://boredzo.org/blog/archives/2007-01-06/longest-common-prefix-in-python-2#comment-6812</link>
		<dc:creator>Peter Hosey</dc:creator>
		<pubDate>Mon, 29 Jan 2007 03:53:10 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/archives/2007-01-06/longest-common-prefix-in-python-2#comment-6812</guid>
		<description>I guess we'll have to agree to disagree on the whitespace—I don't like large gutters on either side of the page, as I consider the space wasted.

I'm not sure what you mean by it being hard to tell posts apart from one another. Are the HR and H2 on each post not doing the job? (No sarcasm meant—I'm asking earnestly.)</description>
		<content:encoded><![CDATA[<p>I guess we'll have to agree to disagree on the whitespace—I don't like large gutters on either side of the page, as I consider the space wasted.</p>
<p>I'm not sure what you mean by it being hard to tell posts apart from one another. Are the HR and H2 on each post not doing the job? (No sarcasm meant—I'm asking earnestly.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nicholas Riley</title>
		<link>http://boredzo.org/blog/archives/2007-01-06/longest-common-prefix-in-python-2#comment-6810</link>
		<dc:creator>Nicholas Riley</dc:creator>
		<pubDate>Mon, 29 Jan 2007 03:25:25 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/archives/2007-01-06/longest-common-prefix-in-python-2#comment-6810</guid>
		<description>It's hard to tell posts apart from one another, and the text uses the entire page width.  Sometimes whitespace is good.</description>
		<content:encoded><![CDATA[<p>It's hard to tell posts apart from one another, and the text uses the entire page width.  Sometimes whitespace is good.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter Hosey</title>
		<link>http://boredzo.org/blog/archives/2007-01-06/longest-common-prefix-in-python-2#comment-6516</link>
		<dc:creator>Peter Hosey</dc:creator>
		<pubDate>Mon, 22 Jan 2007 05:08:24 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/archives/2007-01-06/longest-common-prefix-in-python-2#comment-6516</guid>
		<description>Indeed, genericpath.commonprefix has an awesome implementation. Thanks for the link!

What's hard to read about my website layout? (Other than the fact that all the articles get shunted down below the sidebar half the time. That's a bug that I still haven't figured out; something to do with the wrapping nature of heading elements, I think.)</description>
		<content:encoded><![CDATA[<p>Indeed, genericpath.commonprefix has an awesome implementation. Thanks for the link!</p>
<p>What's hard to read about my website layout? (Other than the fact that all the articles get shunted down below the sidebar half the time. That's a bug that I still haven't figured out; something to do with the wrapping nature of heading elements, I think.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nicholas Riley</title>
		<link>http://boredzo.org/blog/archives/2007-01-06/longest-common-prefix-in-python-2#comment-6514</link>
		<dc:creator>Nicholas Riley</dc:creator>
		<pubDate>Mon, 22 Jan 2007 02:41:48 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/archives/2007-01-06/longest-common-prefix-in-python-2#comment-6514</guid>
		<description>Or, I could learn to read. *sigh*

(In my defense, your website layout is really difficult to read.)</description>
		<content:encoded><![CDATA[<p>Or, I could learn to read. *sigh*</p>
<p>(In my defense, your website layout is really difficult to read.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nicholas Riley</title>
		<link>http://boredzo.org/blog/archives/2007-01-06/longest-common-prefix-in-python-2#comment-6513</link>
		<dc:creator>Nicholas Riley</dc:creator>
		<pubDate>Mon, 22 Jan 2007 02:39:28 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/archives/2007-01-06/longest-common-prefix-in-python-2#comment-6513</guid>
		<description>One minor style nit (which may reduce speed, but improve readability; then again, this is Python, so YMMV :-)

files = [pair[1] for pair in sorted((len(fi), fi) for fi in files)]

I typically use tuple unpacking in this case:

files = [name for length, name in sorted((len(fi), fi) for fi in files))]

OTOH, Python has a function that does exactly what you want: os.path.commonprefix.  It uses min and max in a really neat way I wouldn't have thought of, which is most likely more efficient than sorting the list.

http://svn.python.org/view/python/trunk/Lib/genericpath.py?rev=51719&#38;view=markup</description>
		<content:encoded><![CDATA[<p>One minor style nit (which may reduce speed, but improve readability; then again, this is Python, so YMMV :-)</p>
<p>files = [pair[1] for pair in sorted((len(fi), fi) for fi in files)]</p>
<p>I typically use tuple unpacking in this case:</p>
<p>files = [name for length, name in sorted((len(fi), fi) for fi in files))]</p>
<p>OTOH, Python has a function that does exactly what you want: os.path.commonprefix.  It uses min and max in a really neat way I wouldn't have thought of, which is most likely more efficient than sorting the list.</p>
<p><a href="http://svn.python.org/view/python/trunk/Lib/genericpath.py?rev=51719&amp;view=markup" rel="nofollow">http://svn.python.org/view/python/trunk/Lib/genericpath.py?rev=51719&amp;view=markup</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Wight</title>
		<link>http://boredzo.org/blog/archives/2007-01-06/longest-common-prefix-in-python-2#comment-5304</link>
		<dc:creator>Jonathan Wight</dc:creator>
		<pubDate>Tue, 09 Jan 2007 14:41:31 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/archives/2007-01-06/longest-common-prefix-in-python-2#comment-5304</guid>
		<description>If you take your full complete implementation and pass in:

	files = ['/foo/bar/xyzzy_one', '/foo/bar/xyzzy_two', '/foo/bar/xyzzy_three/four', '/foo/bar/xyzzy_']
 
You get no output.</description>
		<content:encoded><![CDATA[<p>If you take your full complete implementation and pass in:</p>
<p>	files = ['/foo/bar/xyzzy_one', '/foo/bar/xyzzy_two', '/foo/bar/xyzzy_three/four', '/foo/bar/xyzzy_']</p>
<p>You get no output.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.262 seconds -->
