Getting rid of 'nan' from list value of dictionary , python
Question: I have this dictionary:

    
    
    dict_new = 
    {'extracted_layout': [nan, nan, nan, nan, nan, nan, nan, nan, nan, 'shyamanna layout', nan, nan, nan, nan, 'm t s layout', nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, 'green glen layout', nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, 'h s r layout', nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, 'vikas layout', 'annaiah reddy layout', nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, 'andhra muniyappa layout', nan, nan, nan, nan, nan, 'lake city layout', nan, 'h s r layout'}
    

It has one key, `extracted_layout` and its values are in a list that is
stuffed with nans . How do I get rid of them?


Answer: If `nan` is float nan, use
[`math.isnan`](https://docs.python.org/2/library/math.html#math.isnan) to
filter it out:

    
    
    >>> import math
    >>> nan = float('nan')
    >>> nan
    nan
    >>> math.isnan(nan)
    True
    >>> math.isnan(1)
    False
    

* * *
    
    
    import math
    
    dict_new['extracted_layout'] = [
        x
        for x in dict_new['extracted_layout']
        if not (isinstance(x, float) and math.isnan(x))
    ]
    

