Given a nested list representing gradebooks of different courses:
gradebooks = [[['Troy', 92], ['Alice', 95]], [['James', 89], ['Charles', 100], ['Bryn', 59]]]
- Using the builtin
sorted()function, write code to sort courses by course mean. The expected output is
[[['James', 89], ['Charles', 100], ['Bryn', 59]], [['Troy', 92], ['Alice', 95]]]
- Using the builtin
sorted()function, write code to sort students of each course by score in descending order. The expected output is
[[['Alice', 95], ['Troy', 92]], [['Charles', 100], ['James', 89], ['Bryn', 59]]]
I'm having trouble with these questions, I tried to answer the first question using codes below but it doesnt work.
sort1 = sorted(gradebooks, key=lambda x : sum(gradebooks[x]) / len(gradebooks[x]))