How to convert list of tuples into a single list of unique values ?

Skip Montanaro skip at pobox.com
Thu Jan 10 09:22:49 EST 2002


    Kalle> Why the extra append?  To me
    Kalle> P = [x for t in L for x in t if x]
    Kalle> is more obvious.

Whoops, yeah, you're right.  I was originally thinking of using a single for
loop and flattening the tuples:

    P = []
    [P.extend(list(t)) for t in L]

then realized that wouldn't take care of the empty matches.  I modified that
in the obvious way, which led to a suboptimal solution.

-- 
Skip Montanaro (skip at pobox.com - http://www.mojam.com/)




More information about the Python-list mailing list