In article <[EMAIL PROTECTED]>,
 "Lad" <[EMAIL PROTECTED]> wrote:

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

One reasonable option is to use the .sort() method of a list:

  Emails.sort(key = lambda s: list(reversed(s.split('@'))))

The "key" parameter specifies how to obtain a sort key from each element 
in the source list.

Cheers,
-M

-- 
Michael J. Fromberger             | Lecturer, Dept. of Computer Science
http://www.dartmouth.edu/~sting/  | Dartmouth College, Hanover, NH, USA
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to