List comprehensions are great. Is there an elegant, slick way to do a list comprehension that appends items to each other as they go, rather than putting them all in a list?
IE, I have some comprehension [func(x) for x in y if z]
that spits out [['a','b'],['c','d'],['e','f']]
, what can i write to instead spit out ['a','b','c','d','e','f']
?
Obviously I could do
alist = []
for x in y:
if z:
alist += func(x)
but that's four or five lines of code! it feels like there must be a way to do it that's as simple and easy as the list comprehension is.