This feels like a simple question, but I haven't been able to figure it out and I haven't been able to find the answer anywhere.
In one line, how can I use two identical list comprehensions on two different lists, and return the results as two seperate lists?
I am trying to do this:
listx = [x for x in listx if x != None]
listy = [y for y in listy if y != None]
Is there a way to do this in one line? Perhaps using map()
or a list comprehension?
Though I don't get why it has to be a one-liner, this should do what you want:
listx, listy = [[x for x in alist if x != None] for alist in [listx, listy]]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With