Python Forum
finding the closest floating point number in a list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
finding the closest floating point number in a list
#1
i am not asking for anyone to code this for me. i'm just wanting to know if there might be an already existing tool out there to do this. otherwise i'll code it myself.

i have a big list of tuples. the first item in each tuple is a floating point number. the remaining items in each tuple are items with association to that first item. the list is sorted. there may be tuples with exactly the same first item, and the order of these does not matter.

i need a function that is given a floating point number and with that number, needs to find the tuple with the closest first item. if adjacent tuples are exactly the same, the function needs to return a list of all that have exactly identical first items that meet the requirement of being closest.

i might redo this all using decimal.Decimal type instead of float.

speed is not important. the lookup will be rarely done, maybe a few dozen times at boot-up and once every few hours thereafter. if it takes a couple seconds to run, no big deal. the list will be just a few thousand in length at most.

i've imagined a few ways to optimize this lookup. but this is not needed in this case. sequential is sufficient.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Messages In This Thread
finding the closest floating point number in a list - by Skaperen - Sep-13-2019, 02:27 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Error is finding mean of a list PythonBoy 4 923 Sep-11-2023, 02:38 PM
Last Post: PythonBoy
  Delete strings from a list to create a new only number list Dvdscot 8 1,547 May-01-2023, 09:06 PM
Last Post: deanhystad
  find random numbers that are = to the first 2 number of a list. Frankduc 23 3,249 Apr-05-2023, 07:36 PM
Last Post: Frankduc
  Finding combinations of list of items (30 or so) LynnS 1 885 Jan-25-2023, 02:57 PM
Last Post: deanhystad
  Finding the price based on industry and number of transactions chandramouliarun 0 914 Jul-26-2022, 07:36 PM
Last Post: chandramouliarun
  TypeError: float() argument must be a string or a number, not 'list' Anldra12 2 4,886 Jul-01-2022, 01:23 PM
Last Post: deanhystad
Question Finding string in list item jesse68 8 1,887 Jun-30-2022, 08:27 AM
Last Post: Gribouillis
  Split a number to list and list sum must be number sunny9495 5 2,305 Apr-28-2022, 09:32 AM
Last Post: Dexty
  Divide a number by numbers in a list. Wallen 7 8,055 Feb-12-2022, 01:51 PM
Last Post: deanhystad
  finding point in m grid jenya56 0 826 Feb-06-2022, 09:00 PM
Last Post: jenya56

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020