Oct-16-2018, 01:22 AM
(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.