Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4331170
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:04:12+00:00 2026-05-21T10:04:12+00:00

Suppose chest is a list of coordinates that are two item lists. For example

  • 0

Suppose chest is a list of coordinates that are two item lists.

For example chest = [[2,4], [4,5], [1,3]]

With the function below, I want the distance between the point (x,y) and each of the chest points. So as it is, the function would return these three distances, right? But my question is, how do I return only the smallest (or largest) result from these three values? Is there any way to do this without creating a new list of distances?

def makeMove(board, chest, x, y):

for cx, cy in chests:
    distance = sqrt(abs((x-cx)**2) + abs((y-cy)**2)))
    return distance
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T10:04:13+00:00Added an answer on May 21, 2026 at 10:04 am

    You could use max() or min() plus a generator expression…

    return max(
        sqrt( abs(x - cx) + abs(y - cy) )
        for cx, cy in chests)
    

    Also note that as an optimization, you may prefer to do this instead (since if sqrt(x) > sqrt(y), then x > y) to reduce the number of sqrt calls:

    return sqrt(max(
        abs(x - cx) + abs(y - cy)
        for cx, cy in chests))
    

    (Also, are you sure you don’t want to be squaring the distances instead of abs()ing them? The normal distance formula is sqrt((x-x')^2 + (y-y')^2)…)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The catch: only comparisons between elements of the list is allowed. For example, suppose
Suppose I have an IEnumerable such as a List(TValue) and I want to keep
Suppose that a table named SuplProd has the columns supplier and product and two
Suppose I have a class that doesn't support memberwise copying so I don't want
Suppose, in MATLAB, that I have a matrix, A, whose elements are either 0
Suppose I have a list, in which no new nodes are added or deleted.
Suppose you have a subsystem that does some kind of work. It could be
http://clifgriffin.com/blockade2/ Ok, I have an unordered list that serves as a list of menu
Suppose I have a data frame, df, that looks like: f t1 t2 t3
Suppose there is a MySQL user alice that is currently connected to the database.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.