Sort by domain name?

js ebgssth at gmail.com
Mon Oct 2 18:30:55 CEST 2006


> How about sorting the strings as they are reversed?
>
> urls = """\
> http://mail.google.com
> http://reader.google.com
> http://mail.yahoo.co.uk
> http://google.com
> http://mail.yahoo.com""".split("\n")
>
> sortedList = [ su[1] for su in sorted([ (u[::-1],u) for u in urls ]) ]
>
> for url in sortedList:
>     print url
>
<snip>
>
> Close to what you are looking for, might be good enough?

Great... I couldn't thought that way. Thanks a lot!



More information about the Python-list mailing list