Looking through a list for a certain or relatively close value
Question: I have a csv file that looks like this:

    
    
    Type     Mag     ra     dec
    3        24.6    223.2  50.833
    6        24.5    223.19 50.834
    

With more than 500 values per column. I want to look for a certain value and
anything close to it. I have the values 223.2516 for the ra and 58.0538 for
the dec. These values were converted and they may not be exactly like this in
the csv data file. I therefore, want anything that's close to the values I'm
looking for. If I'm looking for 223.2516 then anything that has at least
223.25 should come out as a result this way i can compare which one is the
closest.

All I have now is to ask python to do a search i.e.

    
    
    223.2516 in [row[2] for row in data]
    

But this only returns true of this exact value is there which may or may not
be there. Like I said, I want all values that are close to that one with the
first 5 numbers: "223.25".

I tried adding an asterisk after 223.25 as such

    
    
    223.2 * in [row[2] for row in data]
    

but all I get is

    
    
    File "<ipython-input-16-d185380219a6>", line 1
        223.2 * in [row[2] for row in data]
             ^
    SyntaxError: invalid syntax
    

Here's the whole code:

    
    
    import numpy
    from matplotlib import *
    from pylab import *
    
    data = np.genfromtxt('result.csv',delimiter=',',skip_header=1, dtype=float)
    223.2516 in [row[2] for row in data]
    

The value to be found will obviously be through user input, I just haven't
added that part yet. Any help is appreciated


Answer: yes, what you want is something like:

    
    
    arr = r_[1:10]
    [a for a in arr if abs(a-5) < 2 ]
    

This results in [4,5,6], for example.

