How can I iterate over and modify the values in a dict?
Another way
records.update((k, 0) for k,v in records.iteritems() if v is None)
Example
>>> records
{'bar': None, 'baz': 1, 'foo': None}
>>> records.update((k, 0) for k,v in records.iteritems() if v is None)
>>> records
{'bar': 0, 'baz': 1, 'foo': 0}
for k in records:
if records[k] is None:
records[k] = 0
Try
for key, value in records.iteritems():
if value is None:
records[key] = 0