Mar-16-2023, 04:30 PM
(This post was last modified: Mar-16-2023, 07:28 PM by deanhystad.)
The comprehension (for the OP) would be like this:
class C: def __init__(self, size): self.list_of_ds = list(range(size)) class B: def __init__(self, size): self.list_of_cs = [C(size + 1) for _ in range(size)] class A: def __init__(self, size): self.list_of_bs = [B(size + 1) for _ in range(size)] a = A(2) print([d for b in a.list_of_bs for c in b.list_of_cs for d in c.list_of_ds])
Output:[0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3]