Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
organizing by distance
#7
(Oct-16-2018, 12:28 AM)stullis Wrote: First, there are a couple things to adjust before getting to the problem at hand. All the lines from 53 down should not be in the for loop started on line 15. By having those lines under that, the script will perform the other loops and assessments repeatedly when we only have to do them once (plus, I believe list.sort() is a bubble sort which is has poor performance in the first place; let's not do that over and over again).

Lines 53 through the end should not be in the with body either. By the time we get to those lines, we're done with the file so let's get rid of the file and free up some memory before running those lines.

The function on line 53... I would move it to the top. I had it right before its call for demonstration purposes. For implementation, I would put it at the top so it gets defined once and then called later.

Likewise for line 3, imports should be at the very top of your file. The layout should be imports at the top, followed by class and function definitions, and finally some implementation code (if present).

As for the problem... what exactly is happening? I suspect that you aren't getting five or fewer results printed. Perhaps the sortByDistance function needs a revisit too though that should already be working.

THANK YOU! That really fixed a lot of problems, But how do I limit the number of printed results in this case? since 'x[2]' is printing out the 3rd column. I only need the first 5.
Reply


Messages In This Thread
organizing by distance - by gonzo620 - Oct-10-2018, 11:27 PM
RE: organizing by distance - by stullis - Oct-11-2018, 01:55 AM
RE: organizing by distance - by gonzo620 - Oct-11-2018, 03:55 AM
RE: organizing by distance - by stullis - Oct-11-2018, 11:27 AM
RE: organizing by distance - by gonzo620 - Oct-15-2018, 04:30 PM
RE: organizing by distance - by stullis - Oct-16-2018, 12:28 AM
RE: organizing by distance - by gonzo620 - Oct-16-2018, 01:22 AM
RE: organizing by distance - by stullis - Oct-16-2018, 01:41 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Organizing several similar classes with overlapping variables 6hearts 7 1,489 May-07-2023, 02:00 PM
Last Post: 6hearts
  Organizing list of objects by attribute scarney1988 3 2,272 Mar-11-2020, 03:55 PM
Last Post: scarney1988
  Visualize Geo Map/Calculate distance zarize 1 1,932 Dec-05-2019, 08:36 PM
Last Post: Larz60+
  Organizing Data in Dictionary Ranjirock 3 2,683 Aug-27-2019, 02:48 PM
Last Post: Ranjirock
  euclidean distance jenya56 3 2,889 Mar-29-2019, 02:56 AM
Last Post: scidam
  Organizing tips Demini 1 2,258 Feb-10-2018, 05:32 AM
Last Post: metulburr
  Python Ble Distance Problem aleynasarcanli 10 12,660 Feb-09-2018, 10:48 PM
Last Post: aleynasarcanli
  Organizing results acmichelman 2 3,321 Sep-05-2017, 06:39 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

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