If Dict Contains...

Daniel Nogradi nogradi at gmail.com
Wed Apr 25 05:36:17 EDT 2007


> Looking to build a quick if/else statement that checks a dictionary for a
> key like follows.
>
> If myDict contains ThisKey:
>
>                 Do this...
>
> Else
>
>                 Do that...
>
>
>
> Thats the best way of doing this?


if key in myDict:
    Do this.....
else:
    Do that....


HTH,
Daniel



More information about the Python-list mailing list