0

Do you of you know what the "approximately equal to" operand is? I need to find numbers in a list that are approximately equal to a fixed number that I have defined. I tried doing =~ and == ~float but did not work. Below is the sample code of what I trying to do. Thanks in advance!

for c1 in range(len(path_Limon_Lib_Chorotega)):
for c2 in range(len(path_Limon_Lib_Chorotega[c1][0])):
    if path_Limon_Lib_Chorotega[c1][0][c2] == ~11.264:
    # if path_Limon_Lib_Chorotega[c1][0][c2] > 11.264 and path_Limon_Lib_Chorotega[c1][0][c2] < 60.8:
        coords_Limon_Lib_Chorotega[c1].append(
            (
                path_Limon_Lib_Chorotega[c1]["Lat"][c2],
                path_Limon_Lib_Chorotega[c1]["Long"][c2]
            )
        )
Alexander
  • 59,041
  • 12
  • 98
  • 151
  • 1
    Can you define approximately? Give us some sample numbers please. – Chris Sep 20 '21 at 13:56
  • 2
    There isn't an operator, but there is `math.isclose`. Does this answer your question? https://stackoverflow.com/q/558216/3141234 – Alexander Sep 20 '21 at 13:56
  • 1
    does this post help? https://stackoverflow.com/questions/5595425/what-is-the-best-way-to-compare-floats-for-almost-equality-in-python – G Ritchie Sep 20 '21 at 13:56
  • 1
    [`math.isclose()`](https://docs.python.org/3/library/math.html#math.isclose) (see https://stackoverflow.com/questions/558216/function-to-determine-if-two-numbers-are-nearly-equal-when-rounded-to-n-signific) – Green Cloak Guy Sep 20 '21 at 13:56
  • 1
    You would want to look at the [`math.isclose()`](https://docs.python.org/3/library/math.html#math.isclose) method. – blackbrandt Sep 20 '21 at 13:56

0 Answers0