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

pekka niiranen krissepu at vip.fi
Thu Jan 10 08:19:55 EST 2002


Of course you are right about the syntax of my handwritten example.

 This list is cut from idle's output:

L = [('?AA?BB!CC!', '?BB!'), ('?DD!', ''), ('?EE!', ''), ('?FF?GG!HH!', '?GG!')]

The resulting list should be:

P = ['?AA?BB!CC!', '?BB!', '?DD!', '?EE!','?FF?GG!HH!' '?GG!']

As you can see, I would not like to have empty values in my list.
Maybe filter(None, L) can be used.
   

Steve Holden wrote:

>"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/
>
>
>
>
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20020110/c06aed23/attachment.html>


More information about the Python-list mailing list