[Tutor] sorting file paths made up of of strings and numbers

Emad Nawfal (عماد نوفل) emadnawfal at gmail.com
Wed Apr 15 02:18:32 CEST 2009


On Tue, Apr 14, 2009 at 8:10 PM, wesley chun <wescpy at gmail.com> wrote:

> > How can I sort the following list in a way that takes care of the right
> > order of numbers? The sorted function compares strings here as far as I
> can
> > see, but I want to have filepath2 follow filepath1. Your help is
> > appreciated.
> >>>> myList
> > ['filepath54', 'filepath25', 'filepath49', 'filepath0', 'filepath89',
> > 'filepath52', 'filepath37', 'filepath32', 'filepath2', 'filepath15',
> >        :
> > 'filepath91', 'filepath85', 'filepath9', 'filepath59', 'filepath10',
> > 'filepath30', 'filepath31', 'filepath80', 'filepath42', 'filepath74',
> > 'filepath21']
>
>
> unfortunately, we're restricted from solving your homework problems
> for you, however, we can tell you that you can still use sorted().
> just combine that with operator.itemgetter(), and you should be well
> on your way to solving your problem!
>
> hope this helps!
> -- wesley
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> "Core Python Programming", Prentice Hall, (c)2007,2001
> "Python Fundamentals", Prentice Hall, (c)2009
>    http://corepython.com
>
> wesley.j.chun :: wescpy-at-gmail.com
> python training and technical consulting
> cyberweb.consulting : silicon valley, ca
> http://cyberwebconsulting.com
>

Thank you so much Wesley for the tip. I'll look into itemgetter()
This is not a homework problem though,  but I'm working on a paper in which
this is useful. So, it is related to school, but is by no means a homework.

-- 
لا أعرف مظلوما تواطأ الناس علي هضمه ولا زهدوا في إنصافه كالحقيقة.....محمد
الغزالي
"No victim has ever been more repressed and alienated than the truth"

Emad Soliman Nawfal
Indiana University, Bloomington
--------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090414/56b6a1e1/attachment.htm>


More information about the Tutor mailing list