Perl and Python, a practical side-by-side example.

William Heymann kosh at aesaeion.com
Sat Mar 3 04:26:29 EST 2007


On Saturday 03 March 2007, Ben Finney wrote:
> Bjoern Schliessmann <usenet-mail-0306.20.chr0n0ss at spamgourmet.com> writes:
>
>     if not recs.has_key(piid):      # [1]
>
Why not

if piid not in recs:

That is shorter, simpler, easier to read and very slightly faster. Plus you 
can change the data structure of recs later without changing that line so 
long as it implements containment testing.




More information about the Python-list mailing list