[Tutor] Dictionary Error: 'dict' object has noattribute '_contains_'
Alan Gauld
alan.gauld at freenet.co.uk
Sun Nov 6 23:01:23 CET 2005
> I used to want that syntax when I started, now I stick to for x in
> y.keys()
I knew you could do
for item in dictionary:
instead of
for item in dictionary.keys():
But I didn't realise it worked for a single item test too
if item in dictionary
instead of
if dictionary.has_key(item):
While the loop is probably as easy to read either way
the test is much cleaner using 'in'.
Nice.
Alan g.
More information about the Tutor
mailing list