I have a list of objects, known as Bricks, I want to check the attributes of all objects in the list. I tried:
pos = [Brick.start_pos for Brick in self.brick_list]
to create a list of the required attribute i.e start_pos, but it populates a list with only the attribute of the last brick in the brick_list. I am using python 3.4. I need to do this for a lot of different attributes so a comprehension makes sense to me.
Brick class is mostly just a holder for data and is defined:
class Brick:
def __init__(self, start_pos=0, current_pos=0, variety=0, moveability=0,
neighbours=0, max_range=0, sides=0, rotation=0, length=0,
previous_pos =0):
self.start_pos = start_pos
self.current_pos = current_pos
self.moveability = moveability
self.variety = variety
self.neighbours = neighbours
self.max_range = max_range
self.sides = sides
self.rotation = rotation
self.length = length
self.previous_pos = previous_pos
with couple very simple functions.
Brick? And how did you build the list?self.brick_list?Brickinstance, repeated n times (n being the length oflister).