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

Steve Holden sholden at holdenweb.com
Thu Jan 10 07:02:45 EST 2002


"pekka niiranen" <krissepu at vip.fi> wrote in message
news:3C3D7AFB.8050505 at vip.fi...
> I have a list of equal size tuples, but a tuple may contain empty values:
>
> t = [ ( a,b,c), (d, ,f) (b,a,j) ]
>
> How can I convert it into a single list of unique values:
>
> l = [a,b,c,d,f,j]
>
> No lambdas, please
>
Point 1: your syntax isn't correct:

>>> t = [ ( a,b,c), (d, ,f) (b,a,j) ]
Traceback (  File "<interactive input>", line 1
    t = [ ( a,b,c), (d, ,f) (b,a,j) ]
                        ^
SyntaxError: invalid syntax

Therefore you'd have to indicate a missing value with an explicit None, or
some sentinel. Supposing you then have

t = [ ( a,b,c), (d,None,f) (b,a,j) ]

you might get a start from

    http://mail.python.org/pipermail/tutor/2001-January/002914.html

regards
 Steve
--
http://www.holdenweb.com/









More information about the Python-list mailing list