I am trying to flatten a python3 list that has nan
in it and it is causing an error.
The code I am using to flatten the list is
def flatten(x):
if isinstance(x, collections.Iterable):
return [a for i in x for a in flatten(i)]
else:
return [x]
from Flatten (an irregular) list of lists. It works great for lists like
[1,[123,132], 1]
but it doesn't work on my list [nan, ['fiction', 'flash', 'short-story'], nan, nan, nan]
The nans come from empty spaces in the pandas DataFrame.
I get the error RuntimeError: maximum recursion depth exceeded in cmp