Skip to content
Advertisement

Getting all subitems from a list of items with list comprehension

I have a dataclass foo which has a member item_li: list[item], item is a dataclass which has a member sub_item_li: list[sub_item] I want to return list[sub_item] from a method of foo. I am primarily looking for a solution with list comprehension. I got it already working with the following list comprehension which I split into 2 lines:

JavaScript

Is there a way to achieve that without having to create a list of lists first?

Advertisement

Answer

Oli answered the question:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement