Simple - looking for a way to do an element exists check..
Paul McGuire
ptmcg at austin.rr.com
Fri Feb 22 16:50:53 EST 2008
On Feb 22, 3:38 pm, Paul Rubin <http://phr...@NOSPAM.invalid> wrote:
> Paul McGuire <pt... at austin.rr.com> writes:
> > I think you have this backwards. Should be:
>
> > if not any(x[0]==element[0] for x in a):
> > a.append(element)
>
> I think you are right, it was too early for me to be reading code when
> I posted that ;-)
I'm still getting used to 'any' and 'all' as new Python built-ins -
but they'll do the short-circuiting as well as a for-loop-with-break.
But I think a set- or dict-based solution will still surpass a list-
based one for the OP.
-- Paul
More information about the Python-list
mailing list