Write a function named "sort_by_product" that takes a list/array of lists/arrays as a parameter where each of the values of input is a list containing 6 floating point numbers. Sort the input based on multiplication of the sixth and second values in each list

Respuesta :

Limosa

Answer:

Following are the program in the Python Programming Language:

def sort_by_product(products): #define function

   products.sort(key=lambda x: x[4] * x[1]) #solution is here

   return products  #return products

#set list type variable

product = [  

   [1, 2, 9, 1, 1, 2],

   [1, 7, 9, 9, 7, 2],

   [1, 1, 9, 5, 2, 2],

   [1, 5, 9, 4, 6, 2],

]

sort_by_product(product)  #call function

print(product)  #print result

Explanation:

Here, we define function "sort_by_product" and pass an argument inside it.

  • inside the function we sort the list and writr the following solution in it.
  • we return the value of products

Then, we set the list type variable 'product' then, call the function.