0

I have this code:

def find_smallest_circle_sqtime(list):
    inv_number_of_elements = 1.0 / len(list);
    smallest_circle = MyCircle(inv_number_of_elements * sum(p.get_x() for p in list),
                               inv_number_of_elements * sum(p.get_y() for p in list), .1);

    smallest_circle.radius = max(smallest_circle.centre.sub(p).norm() for p in list);
    return smallest_circle

Where I'm getting the radius of the farthest point in list relative to the smallest_circle.centre. But actually I need to get the point itself. How can I do that in the most pythonic way?

1 Answer 1

5

The max function allows you to provide a custom ordering function (via the key argument):

max(list, key=lambda p: smallest_circle.centre.sub(p).norm())

And please don't use semicolons. And you shouldn't use names of built-in types/functions as variable names.

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for the answer, it worked. I'm still new to python and semicolons are kind of habbit. Do they make any harm to a program?
You're right about built-in name, of course. Thank you
@AndrewLavq no, they're just superfluous.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.