You may supply your own "default" value : fromkeys « Dictionary « Python Tutorial






d = dict.fromkeys(['name', 'age'], '(unknown)') 
d.get('name', 'N/A') 

# If the key is there, get works like ordinary dictionary lookup: 

d = dict.fromkeys(['name', 'age'], '(unknown)') 

d['name'] = 'Eric' 
print d.get('name') 

ddict = {}.fromkeys(('x', 'y'), -1)
print ddict
edict = {}.fromkeys(('foo', 'bar'))
print edict








8.9.fromkeys
8.9.1.fromkeys method creates a new dictionary with the given keys, each with a default corresponding value of None
8.9.2.If you don't want to use None as the default value, you can supply your own default
8.9.3.get method is a way of accessing dictionary items.
8.9.4.You may supply your own "default" value
8.9.5.Create dictionary from fromkeys() function