I am trying to add objects to lists that are values ββin defaultdict:
dic = defaultdict(list) groups = ["A","B","C","D"]
Therefore, I want to collect all the records belonging to one group in this dictionary, using the group name as a key and a list of all related objects as a value.
But the above code raises an AttributeError:
dic[mygroup] = dic[mygroup].append(entry) AttributeError: 'NoneType' object has no attribute 'append'
It looks like for some reason the values ββare not recognized as lists?
Is there a way to add to lists used as values ββin a dictionary or defaultdict? (I tried this with the usual dict before, and got the same error.)
Thanks for any help! Lastalda
Lastalda
source share