Quick way to append non-blank elements in a list to another list?

I have Python 3.12 on Windows 10.

If I have list1 and list2, I would like a quick way to append non-blank items in list1 into list2. Example.

Below is how I do it now. Is there a list comprehension that might do this?

list1 = ['one', '', 'two', '', 'three']
list2 = ['new']
for l in list1: 
    if l: 
        list2.append(l)
# list2 will be: ['new', 'one', 'two', 'three']

Thank you.

list2 = [e for e in list2 + list1 if e]
2 Likes

You could also do

list2.extend(_ for _ in list1 if _)
2 Likes

Here’s a third way:

list2.extend(filter(None, list1))
3 Likes

list2 += [e for e in list1 if e]