I have 4 objects.
class MyObject:
def __init__(self, id: int, result_name: str):
self.id = id
self.result = Result(result_name)
class Result:
def __init__(self, name: str):
self.name = name
object1 = MyObject(1, 'A')
object2 = MyObject(2, 'A')
object3 = MyObject(3, 'B')
object4 = MyObject(4, 'B')
They're stored in a tuple:
x_ids = (object1, object2, object3, object4)
I want bases on parameters:
[x.result.name for x in x_ids]
>> ("A", "A", "B", "B")
Have list of resulting list, just two objects with "A", and "B" attribute
result = (object(1or2), object(3or4))
How can I achieve it with list comprehensions?