Guest User

Untitled

a guest
Oct 21st, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. class Container():
  2.  
  3. def __init__(self,list0,list1):
  4. self.list0,self.list1=list0,list1
  5. self.pairs=zip(list0,list1)
  6. self.items=dict(self.pairs)
  7.  
  8. ...
  9.  
  10. def __add__(self,key,value):
  11. dictionary=self.items
  12. other = other if type(other)==dict else other.items
  13. for k in other.keys():
  14. dictionary[k]=other[k]
  15. return dictionary
  16.  
  17. ...
  18.  
  19. def __iadd__(self,other):
  20. self.items=self+other
  21.  
  22. # >>> c2 = Container([11,12,13],['k','l','m'])
  23. # >>> print container + c2
  24. # {0: 'j', 1: 'a', 2: 'b', 3: 'c', 4: 'd', 5: 'e', 6: 'f', 7: 'g', 8: 'h', 9: 'i', 11: 'k', 12: 'l', 13: 'm'}
  25. #
  26. # Note: at this time the container does not equal None.
  27. #
  28. # >>> container+=c2
  29. # >>> print container
  30. # None
Add Comment
Please, Sign In to add comment