How to sort list

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Tue Nov 21 20:46:46 CET 2006


> Emails=['a at hotmail.com','a at yahoo.com','b at hotmail.com','c at yahoo.com',....]
> after sorting I would like to have
> Emails=['a at hotmail.com','b at hotmail.com','a at yahoo.com','c at yahoo.com',....]

This problem isn't easy to solve in the general way, this is a first
try:

emails = ['a at hotmail.com','a at yahoo.com','b at hotmail.com','c at yahoo.com']

print sorted(emails, key=lambda em: em.split("@")[::-1])

Bye,
bearophile




More information about the Python-list mailing list