Guest User

Untitled

a guest
Nov 16th, 2014
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.64 KB | None | 0 0
  1. >>> class dict_(dict):
  2.     def append(self,*args):
  3.             for arg in args:
  4.                 if arg and  type(arg)==dict:
  5.                     for i in arg.iteritems():
  6.                         key = i[0]
  7.                         value = i[1]
  8.                         self[key] = value
  9.                 else:
  10.                     raise Exception("Not a dictionary.")
  11.  
  12.                
  13. >>> x = dict_({4:3})
  14. >>> x.append(5)
  15.  
  16. Traceback (most recent call last):
  17.   File "<pyshell#136>", line 1, in <module>
  18.     x.append(5)
  19.   File "<pyshell#134>", line 10, in append
  20.     raise Exception("Not a dictionary.")
  21. Exception: Not a dictionary.
  22. >>> x.append({11:11},{12:12})
  23. >>> x
  24. {12: 12, 11: 11, 4: 3}
  25. >>> x.append({433:23,223:12})
  26. >>> x
  27. {12: 12, 11: 11, 4: 3, 223: 12, 433: 23}
Advertisement
Add Comment
Please, Sign In to add comment