Guest User

Untitled

a guest
Dec 16th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. class Unit:
  2. x = 0
  3. y = 0
  4. range = 0
  5.  
  6. def __init__(self, x, y, range):
  7. self.x = x
  8. self.y = y
  9. self.range = range
  10.  
  11. test1 = Unit(10, 10, 5)
  12. test2 = Unit(20, 20, 5)
  13. test3 = Unit(30, 30, 7)
  14.  
  15. test_list = [test1, test2, test3]
  16.  
  17. test_list_attr = [test1.y, test2.y, test3.y]
  18.  
  19. test_list_attr = [i.y for i in test_list]
  20.  
  21. from operator import attrgetter
  22.  
  23. test_list_attr = list(map(attrgetter('y'), test_list))
Add Comment
Please, Sign In to add comment