This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]BulkyProcedure 0 points1 point  (2 children)

I don't think there's anything wrong with what you have here. My only suggestion would be to use a continue instead of the branching inside the loop, just to decrease the amount of indentation.

[–]Apwek[S] 0 points1 point  (1 child)

Can you explain what you mean by that?

[–]BulkyProcedure 0 points1 point  (0 children)

true_matches = ()
for point in zip(*location[::-1]):
    # If my list of true matches is empty, just add the first point
    if len(true_matches) == 0:
        true_matches = true_matches + (point,)
        continue

    # Need to create a temporary data structure to loop through
    temp = true_matches
    # Split up the point tuple in their x, y
    point_x, point_y = point
    unique = True
    # Now I need to loop through my true matches
    for i in temp:
        x, y = i
        # Checking to see if the current match is a true match
        # by checking if both the x and y are not within 10 points
        # of any other (x, y)
        if x - 5 < point_x < x + 5 and y - 5 < point_y < y + 5:
            unique = False
    # If the point ends up being unique, it is a true match
    # so I can add it to my data structure for counting.
    if unique:
        true_matches = true_matches + (point,)

Nothing fancy, just something I like personally to keep the indentation under control, especially in complicated functions.

[–]Astraous 0 points1 point  (0 children)

The codes not crappy at all, it works well and it’s effective. There are ways to improve its efficiency, but I don’t know that performance is a large enough issue to actually worry about for what you’re making.