[Tutor] sorting file paths made up of of strings and numbers
wesley chun
wescpy at gmail.com
Wed Apr 15 02:10:20 CEST 2009
> 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
More information about the Tutor
mailing list