Question

In: Computer Science

lines = [ { "name": "student19", "test1": "70", "test2": "70", "test3": "83", "test4": "99", "test5": "97"...

lines = [ { "name": "student19",
"test1": "70",
"test2": "70",
"test3": "83",
"test4": "99",
"test5": "97"
},
{
"name": "student20",
"test1": "68",
"test2": "68",
"test3": "81",
"test4": "74",
"test5": "76"
},
{
"name": "student21",
"test1": "74",
"test2": "73",
"test3": "84",
"test4": "84",
"test5": "69"
},]

I need to sort the test3 only in descending order using python lambda function.

it should look like something like this:

l_func=lambda line: here goes the function

return output=sorted(lines, key=l_func)

thanks

Solutions

Expert Solution

So we need to sort this array of dicts acording to the test3 value only and in descending order, it means dicts with greater value of test3 will come first and dicts with least value of test3 will come last.

Have a look at the below code. I have put comments wherever required for better understanding.

lines = [ { "name": "student19",
"test1": "70",
"test2": "70",
"test3": "83",
"test4": "99",
"test5": "97"
},
{
"name": "student20",
"test1": "68",
"test2": "68",
"test3": "81",
"test4": "74",
"test5": "76"
},
{
"name": "student21",
"test1": "74",
"test2": "73",
"test3": "84",
"test4": "84",
"test5": "69"
},]

# This is the lambda function which will sort the array by test3 value
l_func = lambda x:x["test3"]
# since we need it in descending order, we will add an extra parameter of reverse and will set it to True
output=sorted(lines, key=l_func,reverse = True)

print(output)

Happy Learning!


Related Solutions

Consider the following: X 44 62 83 97 108 Y 214 227 181 123 103 1)...
Consider the following: X 44 62 83 97 108 Y 214 227 181 123 103 1) What is slope of the regression line predicting Y from X, rounded to 2 decimal places? 2) What is the intercept of the regression line predicting Y from X, rounded to 2 decimal places? 3) What is the correlation between X and Y, rounded to 2 decimal places?
96. Name three indicators of chemical change. 97. Make the following conversions:
96.   Name three indicators of chemical change.97.   Make the following conversions:   a.   66.5 mm to micrometers   b.   4 × 10−2 g to centigrams   c.   5.62 mg/mL to decigrams per liter   d.   85 km/h to meters per second98.   How many significant figures are in each measurement?   a.   0.00052 m   b.   9.8 × 104 g   c.   5.050 mg   d.   8.700 mL99.   How many neutrons are in each atom?   a.   silicon-30   b.   magnesium-24   c.   nitrogen-15   d.   chromium-50100.   How do isotopes of an atom...
X 28 39 32 37 44 22 40 Y 83 108 97 108 107 74 114...
X 28 39 32 37 44 22 40 Y 83 108 97 108 107 74 114 The standard error of the estimate for the above bivariate data is: Question 3 options: 5.45 5.65 5.85 6.05
Name and describe the body’s three lines of defense for immunity. Name and describe the five...
Name and describe the body’s three lines of defense for immunity. Name and describe the five major types of white blood cells. What are their lab values? Local inflammation generally produces what classic signs? Describe the multistep process of inflammation.
a) The pulse rates of ten adult women were found to be as follows:                     83    58  70  56 &nbsp
a) The pulse rates of ten adult women were found to be as follows:                     83    58  70  56  76  64  80  76  64  83 Assume that the pulse rate of women is normally distributed. At a 5% level of significance can you conclude that that the true pulse rate of women is less than 72? B) The costs associated with conducting interviews for a job opening have skyrocketed over the years. According to a Harris interactive survey, 211 of 502 senior human resources executives at U.S companies believe that...
For Tc-98, Tc-97, and Tc-96 what are the following for each? Atomic Symbol Name Number of...
For Tc-98, Tc-97, and Tc-96 what are the following for each? Atomic Symbol Name Number of Protons Number of electrons Mass Number Number of Neutrons Mass of isotopes Percent of abundance
92 99 96 94 94 94 90 95 90 89 89 80 83 88 88 1.  What...
92 99 96 94 94 94 90 95 90 89 89 80 83 88 88 1.  What is the n?   __________ 2.  What is ∑x ? __________ 3.  What is ∑x2? __________ 4.  What is (∑x)2? __________ 5.  What is the range?  __________ 6.  What is the mean?  __________ 7.  What is the median?  __________ 8.  What is the mode?  __________ 9.  What is the variance?  __________ 10.  What is the standard deviation?  __________ 11.  If Kara scored a 90 (x)….What is her Z-score?  __________ 12.  If Sara scored a 95….What is her T-score?  __________ 13.  Mark scored an 88 (one of...
1980s 1990s 2000’s 105 78 99 108 87 131 106 90 83 114 87 95 111...
1980s 1990s 2000’s 105 78 99 108 87 131 106 90 83 114 87 95 111 113 81 111 90 100 115 99 88 114 97 113 102 108 108 123 92 116 This table uses the data file that contains the scores of the winning teams from the final NBA Championship game. I would like to know if the average winning score is the same for each decade listed in the table. Test the claim that the samples all...
Determining the Speed of Sound Name Abstract; Include instead of these lines the objectives of the...
Determining the Speed of Sound Name Abstract; Include instead of these lines the objectives of the lab (what you investigated), the short description of how you did it and the conclusions formulated based on the obtained results. It should be ½ to 1 page long. Picture of the experimental set up Observations Data Table 1: Calculation of sound wavelength Tuning fork frequency f (Hz ) Length, (water level to top of tube) L (m) Diameter of tube, d(m) λ(m) =4(L...
Given the following students' test scores (95, 92, 90, 90, 83, 83, 83, 74, 60, and...
Given the following students' test scores (95, 92, 90, 90, 83, 83, 83, 74, 60, and 50), identify the mean, median, mode, range, variance, and standard deviation for the sample. Write a 500-750-word summary and analysis discussing the results of your calculations. State your results for the sample: the mean, median, mode, range, variance, and standard deviation Explain which method is best for this data set. Why? Conduct a one sample T-test and interpret the results (use a population mean...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT