"js " <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Hi list,
>
> I have a list of URL and I want to sort that list by the domain name.
>
> Here, domain name doesn't contain subdomain,
> or should I say, domain's part of 'www', mail, news and en should be 
> excluded.
>
> For example, if the list was the following
> ------------------------------------------------------------
> http://mail.google.com
> http://reader.google.com
> http://mail.yahoo.co.uk
> http://google.com
> http://mail.yahoo.com
> ------------------------------------------------------------
>
> the sort's output would be
> ------------------------------------------------------------
> http://google.com
> http://mail.google.com
> http://reader.google.com
> http://mail.yahoo.co.uk
> http://mail.yahoo.com
> ------------------------------------------------------------
>
> As you can see above, I don't want to
>
>
> Thanks in advance.

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


Prints:
http://mail.yahoo.co.uk
http://mail.google.com
http://reader.google.com
http://google.com
http://mail.yahoo.com


Close to what you are looking for, might be good enough?

-- Paul 


-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to