Advertisement
beng

Untitled

May 8th, 2015
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.45 KB | None | 0 0
  1. class list_wrapper(object):
  2.   def __init__(self, items):
  3.     self._items = items
  4.  
  5.   def __add__(self, items):
  6.     return list_wrapper(self._items + items)
  7.  
  8.   def __repr__(self):
  9.     return repr(self._items)
  10.  
  11. def maybe_add_to_list(l, foo):
  12.   l += foo
  13.  
  14. l1 = [1, 2, 3]
  15. l2 = list_wrapper([1, 2, 3])
  16.  
  17. maybe_add_to_list(l1, [4, 5, 6])
  18. maybe_add_to_list(l2, [4, 5, 6])
  19.  
  20. print l1
  21. print l2
  22.  
  23. # % python test.py
  24. # [1, 2, 3, 4, 5, 6]
  25. # [1, 2, 3]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement