[Tutor] Bigrams and nested dictionaries

Alan Gauld alan.gauld at freenet.co.uk
Mon Apr 3 21:38:08 CEST 2006


> On Wed, 2006-03-29 at 00:15 -0500, Michael Broe wrote:
> You can check if the dictionary key exists prior to assigning to it:
> 
>>>> if not D.has_key('c'):
> ...    D['c'] = {}
>>>> D['c']['a'] = 1

And since 2.4?

if 'c' in D: ...

Alan G.


More information about the Tutor mailing list