Need Help sorting alphabetically.

Fredrik Lundh fredrik at effbot.org
Thu Dec 21 02:43:34 EST 2000


Greg Jorgensen wrote:
> My proposed solution addresses the original problem as stated:

no, it doesn't.  the *original* poster said:

> alphabetically (I'm not sure that is the correct term)

and then:

> eg:
> m = ['Pg95_100.GIF', 'Pg9_100.GIF', 'Pg95A_100.gif', 'Pg9A_100.gif', 'Pg10_100.gif']
>
> I would like the order to be
>
> ['Pg9_100.GIF', 'Pg9A_100.gif', 'Pg10_100.gif, 'Pg95_100.GIF', Pg95A_100.gif' ]

which indicates that he might not have been using the correct
term after all...

just doing a case-insensitive sort gives you:

['Pg10_100.gif', 'Pg95_100.GIF', 'Pg95A_100.gif', 'Pg9_100.GIF', 'Pg9A_100.gif']

to do what he wanted, you need to parse the strings into something
like (("pg", 9), 100), (("pg", "9", "a"), 100), etc.

see Duncan's post for a reasonable solution.

</F>





More information about the Python-list mailing list