so have class dictlist has args parameter takes in dictionaries , appends them list. professor wants me to override addition function in python add 2 dictlists (both refer list of dictionaries). problem i'm having right returning new dictlist after adding 2 dictlists together.
i can extend both lists together, i'm not quite sure how create new dictlist data have since it's in list. thinking iterating through list , passing each dictionary dictlist, ... i'm not sure how that.
class dictlist(object): def __init__(self, args): self.args = args def __add__(self, other): return dictlist(self.args + other.args)
example:
>>> = dictlist( (dict(a=1), dict(b=2)) ) >>> b = dictlist( (dict(c=3), dict(d=4)) ) >>> c = + b >>> c.args ({'a': 1}, {'b': 2}, {'c': 3}, {'d': 4})