Skip to content

Instantly share code, notes, and snippets.

@lichengwu
Created June 22, 2015 00:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lichengwu/9de4fdea16cca710d40d to your computer and use it in GitHub Desktop.
Save lichengwu/9de4fdea16cca710d40d to your computer and use it in GitHub Desktop.
字典默认值
dt = {}
if "key" in dt:
dt["key"] = 1
else:
dt["key"] += 1
# 默认字典
dt = collections.defaultdict(int)
dt["key"] += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment