Sign Up

Have an account? Sign In Now

Sign In

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here
Sign InSign Up

SIKSHAPATH

SIKSHAPATH Logo SIKSHAPATH Logo

SIKSHAPATH Navigation

  • Home
  • Questions
  • Blog
    • Computer Science(CSE)
    • NPTEL
    • Startup
  • Shop
    • Internshala Answers
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Questions
  • Blog
    • Computer Science(CSE)
    • NPTEL
    • Startup
  • Shop
    • Internshala Answers
Home/Questions/Q 16132
Next
Answered
Pavanagg
  • 0
Pavanagg
Asked: April 25, 20222022-04-25T16:54:57+05:30 2022-04-25T16:54:57+05:30In: Python

Suppose a list contains marks earned in the courses CSE110, …

  • 0

Suppose a list contains marks earned in the courses CSE110, PHY111, and MAT110 of each student consecutively in a nested list form. Your task is to take a course name as input from the user and sort the list based on the marks obtained in that course in order to finally print the names of the students in descending order of marks obtained i.e. from the student who earned the highest marks to the student who earned the lowest.

For example, the list may look like
lst = [ [“Alan”, 95, 87, 91], [“Turing”, 92, 90, 83], [“Elon”, 87, 92, 80], [“Musk”, 85, 94, 90] ]
where for each nested list, 1st index holds the name of the student, 2nd index is total marks earned in the CSE110 course, 3rd index is PHY111 marks and 4th index is MAT110 marks.

=====================================================

Hint:

You may create a function for sorting, and then call it every time when needed instead of rewriting the code.

You may get the data in the individual lists from the given nested list.

=====================================================

Sample Input 1
MAT110

Sample Output 1
Alan
Musk
Turing
Elon

computer science
  • 1 1 Answer
  • 365 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook

    1 Answer

    • Voted
    • Oldest
    • Recent
    1. Best Answer
      ADMIN 2
      2022-04-25T17:05:44+05:30Added an answer on April 25, 2022 at 5:05 pm
      This answer was edited.
      # function that sort the list by the course name
      def sortByCourse(lst, course):
      # if the course is CSE
      if(course == "CSE110"):
      return sorted(lst, key = lambda l: l[1], reverse = True)
      # if the course is PHY
      if(course == "PHY110"):
      return sorted(lst, key = lambda l: l[2], reverse = True)
      # if the course is MAT
      if(course == "MAT110"):
      return sorted(lst, key = lambda l: l[3], reverse = True)


      lst = [["Alan", 95, 87, 91], ["Turing", 92, 90, 83], ["Elon", 87, 92, 80], ["Musk", 85, 94, 90]]
      # take course name as input
      course = input()
      # sort the list using fucntion
      sortedList = sortByCourse(lst, course)
      # print final result
      for c in sortedList:
      print(c[0])
      • 1
      • Reply
      • Share
        Share
        • Share on WhatsApp
        • Share onFacebook
        • Share on Twitter
        • Share on LinkedIn

    Leave an answer
    Cancel reply

    You must login to add an answer.

    Forgot Password?

    Need An Account, Sign Up Here

    Sidebar

    store ads

    Stats

    • Questions 1k
    • Answers 1k
    • Posts 127
    • Best Answers 66
    • LINEAR PROGRAMMING AND OPTIMIZATION TECHNIQUES NOTES
    • What is the Difference Between Section, Article and Aside in HTML5?
    • NPTEL Cloud Computing Assignment 3 Answers 2023
    • NPTEL Ethical Hacking Assignment 3 Answers 2023
    • NPTEL Problem Solving Through Programming In C Week 1 & 2 Assignment Answers 2023

    Explore

    • Recent Questions
    • Questions For You
    • Answers With Time
    • Most Visited
    • New Questions
    • Recent Questions With Time

    Footer

    Sikshapath Logo

    Helpful Links

    • Contact
    • Disclaimer
    • Privacy Policy Notice
    • TERMS OF USE
    • FAQs
    • Refund/Cancellation Policy
    • Delivery Policy for Sikshapath

    Follow Us

    © 2021-23 Sikshapath. All Rights Reserved

    Ads Blocker Image Powered by Code Help Pro

    Ads Blocker Detected!!!

    We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

    Refresh

    Insert/edit link

    Enter the destination URL

    Or link to existing content

      No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.