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

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
  • 243 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 on Facebook
        • 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

    Stats

    • Questions 1k
    • Answers 1k
    • Posts 139
    • Best Answers 65
    • Probability and Statistics NPTEL Assignment answers – Week 1
    • NPTEL Joy of Computing Using Python Week 2 Assignment Answers 2023
    • NPTEL Problem Solving Through Programming In C Assignment 2 Answers 2023
    • NPTEL Problem Solving Through Programming In C Assignment 1 Answers 2023
    • NPTEL Python for Data Science Assignment 1 Answers 2023

    Popular Questions

    • I'M ADMIN

      Internshala ethical hacking final test answers: Question sequence differs but ...

      • 6 Answers
    • AK

      You have a green lottery ticket, with ints a, b, ...

      • 4 Answers
    • mj

      Solve by Gauss Elimination Method 5x+y+z+w=4 ,x+7y+z+w=12 , x+y+6z+w=-5, x+y+z+4w=-6

      • 3 Answers

    Explore

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

    Footer

    Helpful Links

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

    Follow

    © 2021-2022 Sikshapath. All Rights Reserved

    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.