Skip to content

Instantly share code, notes, and snippets.

@sxfmol
Last active June 9, 2021 02:54
Show Gist options
  • Save sxfmol/13866a84e1e1ae8c5acdd24d18c668ba to your computer and use it in GitHub Desktop.
Save sxfmol/13866a84e1e1ae8c5acdd24d18c668ba to your computer and use it in GitHub Desktop.
python常用备忘
tuple to dict:
data = [(u'030944', u'20091123', 10, 30, 0), (u'030944', u'20100226', 10, 15, 0)]
fields = ['id', 'date', 'hour', 'minute', 'interval']
dicts = [dict(zip(fields, d)) for d in data]
嵌套字典:
class Vividict(dict):
def __missing__(self, key):
value = self[key] = type(self)()
return value
pz = Vividict()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment