38. Collections Namedtuple: Hackerrank | Python Solution Explained

preview_player
Показать описание
Hello and welcome to this tutorial on the use of Sets in Python.
#hackerrank #hackerranksolutions #pyhtonhackerrank

Task

Dr. John Wesley has a spreadsheet containing a list of student's , , and .

Your task is to help Dr. Wesley calculate the average marks of the students.

Note:
1. Columns can be in any order. IDs, marks, class and name can be written in any order in the spreadsheet.
2. Column names are ID, MARKS, CLASS and NAME. (The spelling and case type of these names won't change.)

Input Format

The first line contains an integer , the total number of students.
The second line contains the names of the columns in any order.
The next lines contains the , , and , under their respective column names.

Constraints

Output Format

Print the average marks of the list corrected to 2 decimal places.
Рекомендации по теме
Комментарии
Автор

I want to thank you for all of your great videos. I am teaching a basic Python class in my local community and your videos are very useful. Great Job.

hoosierfarmboy
Автор

MARKS, CLASS, NAME, ID = input().split()

I did not know you could do this. It seems it's automatically assigning a variable to each item in the list that split() returns. Very cool.

NateFreestyle
Автор

Could you please explain ...when it takes input how does it stays in the order ???? Very confusing?

ashharrayan
Автор

Could you explain the part where you took input off all the fields in the for loop...how does it stay in the order corresponding to the user's order??

tazinga
Автор

Could the container be created outside the loop?

karasa
Автор

The order of the column names changes in the input. For example, test case 0 has:

ID MARKS NAME CLASS

But test case 1 has:

MARKS CLASS NAME ID

How does the code handle that?

NateFreestyle