Question

In: Computer Science

In Python Create a function called ℎ?????. The function has as arguments a list called ??????...

In Python
Create a function called ℎ?????. The function has as arguments a list called ?????? and a list
call center.
• List ?????? contains lists that represent points.
o For example, if ?????? = [[4,2], [3,2], [6,1]], the list [4,2] represents the point with coordinate ? at 4 and y coordinate at 2, and so on for the other lists. Assume that all lists within points contain two numbers (that is, they have x, y coordinates).
• List ?????? contains two numbers that also represent a point.
o For example, ?????? = [3,3] represents the point with coordinate ? at 3 and with coordinate y at 3.
• The function must return the point in points closest to center according to the distance calculated using the
formula: ???????e = | ?2 - ?1| + | ?2 - ?1|
o For example, if ?????? = [[4,2], [3,2], [6,1]] and ?????? = [3,3], then the function must return [3,2]
(note that according to the formula the distance between the points is:

▪ |4 − 3| + |2 − 3| = 2

▪ |3 − 3| + |3 − 3| = 1

▪ |6 − 3| + |1 − 3| = 5

Solutions

Expert Solution

Code:

def hattan(points,center):
    # calculating all the distances between each points and center
    dist = ([abs(item[0]-center[0]) + abs(item[1]-center[1]) for item in points])

    # getting the position of minimum value in the list
    minpos = dist.index(min(dist)) 
    
    return(points[minpos])  # returning points at minimum index

points = [[4,2], [3,2], [6,1]]
center = [3,3]
print('Requied points: ',hattan(points,center))

Output:

for any doubts, please comment below.


Related Solutions

Python pls create a function called search_position. This function returns a list. team1 = {'Fiora': {'Top':...
Python pls create a function called search_position. This function returns a list. team1 = {'Fiora': {'Top': 1, 'Mid': 4, 'Bottom': 3},'Olaf': {'Top': 3, 'Mid': 2, 'Support': 4},'Yasuo': {'Mid': 2, 'Top': 5},'Shaco': {'Jungle': 4, 'Top': 2, 'Mid': 1}} def search_position(team1): returns [(5, [('Top', ['Yasuo'])]), (4, [('Mid', ['Fiora']), ('Support',['Olaf']), ('Jungle',['Shaco'])])   (3, [('Bottom', ['Fiora']), ('Top', ['Olaf'])]), (2, [('Mid', ['Olaf','Yasuo']), ('Top', ['Shaco'])]), (1, [('Mid', ['Shaco'])])]
IN PYTHON Create a function called biochild.  The function has as parameters the number m...
IN PYTHON Create a function called biochild.  The function has as parameters the number m and the lists biomother and biofather.  The biomother and biofather lists contain 0’s and 1’s.  For example: biomother = [1,0,0,1,0,1] and biofather = [1,1,1,0,0,1]  Both lists have the same length n.  The 0's and 1's represent bits of information (remember that a bit is 0 or 1).  The function has to generate a new list (child).  The child...
Write a Python function that takes a list of string as arguments. When the function is...
Write a Python function that takes a list of string as arguments. When the function is called it should ask the user to make a selection from the options listed in the given list. The it should get input from the user. Place " >" in front of user input. if the user doesn't input one of the given choices, then the program should repeatedly ask the user to pick from the list. Finally, the function should return the word...
In Python Create a function called ????. The function receives a "string" that represents a year...
In Python Create a function called ????. The function receives a "string" that represents a year (the variable with this "String" will be called uve) and a list containing "strings" representing bank accounts (call this list ????). • Each account is represented by 8 characters. The format of each account number is "** - ** - **", where the asterisks are replaced by numeric characters. o For example, “59-04-23”. • The two central characters of the "string" of each account...
Using Python create a script called create_notes_drs.py. In the file, define and call a function called...
Using Python create a script called create_notes_drs.py. In the file, define and call a function called main that does the following: Creates a directory called CyberSecurity-Notes in the current working directory Within the CyberSecurity-Notes directory, creates 24 sub-directories (sub-folders), called Week 1, Week 2, Week 3, and so on until up through Week 24 Within each week directory, create 3 sub-directories, called Day 1, Day 2, and Day 3 Bonus Challenge: Add a conditional statement to abort the script if...
Using Python #Write a function called after_second that accepts two #arguments: a target string to search,...
Using Python #Write a function called after_second that accepts two #arguments: a target string to search, and string to search #for. The function should return everything in the first #string *after* the *second* occurrence of the search term. #You can assume there will always be at least two #occurrences of the search term in the first string. # #For example: # after_second("11223344554321", "3") -> 44554321 # #The search term "3" appears at indices 4 and 5. So, this #returns everything...
In python Define a function called cfb_graph which takes no arguments. Form a directed graph from...
In python Define a function called cfb_graph which takes no arguments. Form a directed graph from the file cfb2010.csv by considering the teams as vertices and creating an edge between team1 and team2 only if team1 defeated team2. You should familiarize yourself with this file before attempting this part. cfb_graph will return a dictionary giving this representation.
USING PYTHON Write a program to create a number list. It will call a function to...
USING PYTHON Write a program to create a number list. It will call a function to calculate the average values in the list. Define main ():                        Declare variables and initialize them                        Create a list containing numbers (int/float)                        Call get_avg function that will return the calculated average values in the list.                                       Use a for loop to loop through the values in the list and calculate avg                        End main()
PYTHON: This is the posted problem: General Instructions Create a function called DeterminePrice that will determine...
PYTHON: This is the posted problem: General Instructions Create a function called DeterminePrice that will determine the cost of purchased software. The price is of the software is $350 per license. However, when purchased in larger quantities a discount is given. For quantites less than 10 copies, there is no discount. For quantities greater than 10 and less than and including 20, a 10% discount is given. For quantities greater than 20 and less than and including 30, a discount...
Python Create a move function that is only defined in the base class called Objects. The...
Python Create a move function that is only defined in the base class called Objects. The move function will take two parameters x,y and will also return the updated x,y parameters.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT