[Tutor] Sorting points on a 2D plane

Luke Paireepinart rabidpoobear at gmail.com
Thu Oct 29 01:03:22 CET 2009

Oops I replied off list twice.  (i wish they would just munge the addresses

On Wed, Oct 28, 2009 at 11:34 AM, Robert Berman <bermanrl at cfl.rr.com> wrote:
What I am looking for is a better, faster approach. I think there would
be a way to build a dictionary but you can't use the X values as keys
since keys must be unique.

Why can't you use the X values?
Just key to a list.
for the data
0 5
0 2
0 1
2 3
2 1
5 2
5 1
Your dictionary would look like:
{0:[5,2,1], 2:[3,1], 5:[2,1]}

After sorting the sublists you could use itertools to reassemble the
original coordinates fairly easily but I still don't think this will be the
most optimal way.

You can't get around sorting to sort values.
So perhaps you could give us the exact code you did (on pastebin if it's
long, try to cut out unnecessary cruft before posting) so we can help you
make it more efficient.  This should be extremely fast if you're doing the
sorting correctly.
Python's sort is really really optimized.

Also, if you can upload a sample input file with a large dataset and
indicate your current running time on the data set and what you're trying to
achieve it will be easier to figure out how to improve your algorithm.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20091028/9ba3741a/attachment.htm>

More information about the Tutor mailing list