Simple - looking for a way to do an element exists check..

Paul McGuire ptmcg at austin.rr.com
Fri Feb 22 20:01:19 CET 2008


On Feb 22, 12:54 pm, Paul Rubin <http://phr...@NOSPAM.invalid> wrote:
> Paul Rubin <http://phr...@NOSPAM.invalid> writes:
> >     if any(x==element[0] for x in a):
> >       a.append(element)
>
> Should say:
>
>      if any(x[0]==element[0] for x in a):
>         a.append(element)

I think you have this backwards.  Should be:

     if not any(x[0]==element[0] for x in a):
        a.append(element)

or

     if all(x[0]!=element[0] for x in a):
        a.append(element)

-- Paul



More information about the Python-list mailing list