Last active
June 9, 2021 02:54
-
-
Save sxfmol/13866a84e1e1ae8c5acdd24d18c668ba to your computer and use it in GitHub Desktop.
python常用备忘
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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