Skip to content

Instantly share code, notes, and snippets.

@shiumachi
Created January 10, 2014 17:59
Show Gist options
  • Save shiumachi/8359272 to your computer and use it in GitHub Desktop.
Save shiumachi/8359272 to your computer and use it in GitHub Desktop.
どんなキーが入っているかわからない辞書のリストの整理方法
data = [{'a' : 100 , 'b' : 50}, {'a': 120}, {'b': 40}]
for i in data:
a = i.setdefault('a', 0)
b = i.setdefault('b', 0)
print("{0},{1}".format(a, b))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment