'Remove all nan from nested list [duplicate]

I'm attempting to remove all nan list items from a nested list

l1= 
[['a', 'b', 'c', 'd', 'e', 'f'],
 [1.0, 2.0, 3.0, 4.0, 5.0, nan],
 ['red', 'orange', 'blue', nan, nan, nan]]

I've tried the following

cleanedList = [x for x in l1 if str(x) != 'nan']

However, this returns the same output



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source