How to sort list

Klaus Alexander Seistrup klaus at
Tue Nov 21 20:23:36 CET 2006

Lad <python at> wrote:

> I have a list of emails and I would like to sorted that list by 
> domains
> E.g.
> If the list is
> Emails=['a at','a at','b at','c at',....]
> after sorting I would like to have
> Emails=['a at','b at','a at','c at',....]
> What is the best/easiest way?



array = []

for addr in Emails:
  (user, domain) = addr.split('@')
  array.append((domain, user, addr))
# end for


SortedEmails = [addr for (user, domain, addr) in array]



Klaus Alexander Seistrup

More information about the Python-list mailing list