Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Unit:
- x = 0
- y = 0
- range = 0
- def __init__(self, x, y, range):
- self.x = x
- self.y = y
- self.range = range
- test1 = Unit(10, 10, 5)
- test2 = Unit(20, 20, 5)
- test3 = Unit(30, 30, 7)
- test_list = [test1, test2, test3]
- test_list_attr = [test1.y, test2.y, test3.y]
- test_list_attr = [i.y for i in test_list]
- from operator import attrgetter
- test_list_attr = list(map(attrgetter('y'), test_list))
Add Comment
Please, Sign In to add comment