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

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Sun Feb 24 02:52:02 EST 2008


On Sat, 23 Feb 2008 17:19:47 -0800, thebjorn wrote:

> On Feb 23, 6:18 pm, Paul Hankin <paul.han... at gmail.com> wrote:
>
>> IMO Jason's solution of testing containment in a generator is better
>> (more readable).
>>     if element[0] not in (x[0] for x in a):
>>         a.append(element)
> 
> It may be more readable (although that's debatable), but it always
> traverses the entire list.

The ``not in`` stops if the element is found.

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list