Python program for arranging the students according to their marks in descending order

Python program for arranging the students according to their marks in descending order

Here's a Python program that arranges students based on their marks in descending order:

# Sample data: Dictionary of students and their marks students = { 'John': 85, 'Alice': 90, 'Bob': 78, 'Diana': 92, 'Eva': 88 } # Sorting students by marks in descending order sorted_students = sorted(students.items(), key=lambda x: x[1], reverse=True) # Displaying the sorted list of students for student, marks in sorted_students: print(f"{student}: {marks}") 

In this program:

  • We have a dictionary students with student names as keys and their marks as values.
  • We use the sorted function to sort the dictionary items based on the marks (which is the second element of each item, hence x[1] in the lambda function). The reverse=True argument ensures descending order.
  • Finally, we print out the sorted list of students and their marks.

More Tags

spinner dynamics-crm-online google-cloud-functions haversine invoke sequelize.js command-line-interface create-react-app apk constructor

More Programming Guides

Other Guides

More Programming Examples