Python Forum
compare and find the nearest element ? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: compare and find the nearest element ? (/thread-39186.html)



compare and find the nearest element ? - mr_gentle_sausage - Jan-14-2023

hello,
I need a little help, I have a list (element has 2 elements(X and Y)), and I need to find, in this list, which element is the nearest of my mouse (we have already X and Y of the mouse).
Can you help me please ?

Also, can you know how can I wrote "move away" for evade if they are bomb in approach ? like " Xbomb - 30px ", can it work ?

PS : I'm french, sorry if I make misstake in my message... Doh


RE: compare and find the nearest element ? - Yoriz - Jan-14-2023

Please show the code you have created so far in code tags.


RE: compare and find the nearest element ? - mr_gentle_sausage - Jan-14-2023

(Jan-14-2023, 09:54 PM)Yoriz Wrote: Please show the code you have created so far in code tags.
what I must put ?
the entire code ?


RE: compare and find the nearest element ? - Yoriz - Jan-14-2023

Show the minimal amount of code required to show the problem you require help with.
For instance how do you represent a list of x and y coordinates, how is the x and y of the mouse represented.
What is a xbomb in relation to the above and what does 30px represent.


RE: compare and find the nearest element ? - DPaul - Jan-15-2023

If your problem is "nearest" match to a list of numbers,
you can easily write a small example program to demonstrate the problem .
While doing that, you may find that the python module "bisect"
comes very close to what you want, if I understand your question correctly.
Paul