News for hackers. Stuff that matters.
Re:Natural sorting by joeyh on Sunday April 04, 2010 @05:35PM (#1240861)
Re:Natural sorting by pavlo on Sunday April 04, 2010 @09:57PM (#1241183)
There is a nice "oneliner" in Ruby for that, created by Piers Cawley: http://j.mp/anfTlJ

And for python there is a nice Article on CodingHorror: http://j.mp/aCxlI3 Hope it's useful :)

Re:Natural sorting by _delirium on Sunday April 04, 2010 @08:53PM (#1241107)
Is there an easy way to get 'ls' to use this ordering?
Re:Natural sorting by inimino on Sunday April 04, 2010 @11:23PM (#1241276)

  ls -v
Re:Natural sorting by _delirium on Sunday April 04, 2010 @11:28PM (#1241284)
Huh, so it seems! Has that been there forever, or was it added semi-recently in response to things like this post?
Re:Natural sorting by inimino on Sunday April 04, 2010 @11:21PM (#1241275)
Available in GNU userland as `sort -V`.
Re:Natural sorting by keefe on Sunday April 04, 2010 @10:44PM (#1241241)
Excellent post. It's focused, unbiased, simple, covers a useful problem and includes source.
Re:Natural sorting by jamesshamenski on Sunday April 04, 2010 @08:49PM (#1241100)
You should sell this to microsoft for millions.
Re:Natural sorting by d0mine on Sunday April 04, 2010 @10:07PM (#1241196)
Is it a sarcasm?

It seems that Microsoft's StrCmpLogicalW() has exactly desired behavior. Besides it is trivial to implement:

  def natural_key(key):
      """See http://www.codinghorror.com/blog/archives/001018.html

      >>> L = 'a01 a9 b1 b10 b9'.split()
      >>> L.sort(key=natural_key)
      >>> ' '.join(L)
      'a01 a9 b1 b9 b10'
      """
      return [int(chunk) if chunk.isdigit() else chunk
              for chunk in re.split(r'(\d+)', key)]