On Thu, Sep 16, 2010 at 1:16 AM, Evert Rol <[email protected]> wrote:
> The latter: they are not the same:
>
>>>> d = {'key': 'food'}
>>>> d['key'] == 'foo'
> False
>>>> 'foo' in d['key']
> True
>
>
> Btw, generally don't use a reserved Python word for a variable, such as dict
> in this case (I know it's an example, but it's still unsafe practice).
>
If you want to find out if 'foo' is a key, you can do: 'foo' in d,
which will return False. I'm not sure, but if I recall this can even
be faster than using the if.
Regards,
Eduardo
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor