How do I use setdefault in python for nested dictionary structures.
eg..
self.table[field] = 0
self.table[date] = []
self.table[value] = {}
I would like to setdefault for these.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Assuming
self.tableis a dict, you could useThe rest are all similar. Note that if
self.tablealready has a keyfield, then the value associated with that key is returned. Only if there is no keyfieldisself.table[field]set to 0.Edit: Perhaps this is closer to what you want:
Instead of keeping track of the count, perhaps just take the length of the list: