Hello Programmers/Coders, Today we are going to share solutions of Programming problems of HackerRank of Programming Language Python. At Each Problem with Successful submission with all Test Cases Passed, you will get an score or marks. And after solving maximum problems, you will be getting stars. This will highlight your profile to the recruiters.
In this post, you will find the solution for Collections.namedtuple() in Python-HackerRank Problem. We are providing the correct and tested solutions of coding problems present on HackerRank. If you are not able to solve any problem, then you can take help from our Blog/website.
Use “Ctrl+F” To Find Any Questions Answer. & For Mobile User, You Just Need To Click On Three dots In Your Browser & You Will Get A “Find” Option There. Use These Option to Get Any Random Questions Answer.
Introduction To Python
Python is a widely-used, interpreted, object-oriented, and high-level programming language with dynamic semantics, used for general-purpose programming. It was created by Guido van Rossum, and first released on February 20, 1991.
Python is a computer programming language often used to build websites and software, automate tasks, and conduct data analysis. It is also used to create various machine learning algorithm, and helps in Artificial Intelligence. Python is a general purpose language, meaning it can be used to create a variety of different programs and isn’t specialized for any specific problems. This versatility, along with its beginner-friendliness, has made it one of the most-used programming languages today. A survey conducted by industry analyst firm RedMonk found that it was the most popular programming language among developers in 2020.
Link for the Problem – Collections.namedtuple() in Python – HackerRank Solution
Collections.namedtuple() in Python – HackerRank Solution
Problem:
collections.namedtuple()
Basically, namedtuples are easy to create, lightweight object types.
They turn tuples into convenient containers for simple tasks.
With namedtuples, you don’t have to use integer indices for accessing members of a tuple.
Example :
Code 01
>>> from collections import namedtuple >>> Point = namedtuple('Point','x,y') >>> pt1 = Point(1,2) >>> pt2 = Point(3,4) >>> dot_product = ( pt1.x * pt2.x ) +( pt1.y * pt2.y ) >>> print dot_product 11
Code 02
>>> from collections import namedtuple >>> Car = namedtuple('Car','Price Mileage Colour Class') >>> xyz = Car(Price = 100000, Mileage = 30, Colour = 'Cyan', Class = 'Y') >>> print xyz Car(Price=100000, Mileage=30, Colour='Cyan', Class='Y') >>> print xyz.Class Y
Task :
Dr. John Wesley has a spreadsheet containing a list of student’s IDs, Marks, class and name.
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 N, the total number of students.
The second line contains the names of the columns in any order.
The next N lines contains the marks, IDs, name and class, under their respective column names.
Constraints :
- 0 <= N <= 100
Output Format :
Print the average marks of the list corrected to 2 decimal places.
Sample Input :
TESTCASE 01
5 ID MARKS NAME CLASS 1 97 Raymond 7 2 50 Steven 4 3 91 Adrian 9 4 72 Stewart 5 5 80 Peter 6
TESTCASE 02
5 MARKS CLASS NAME ID 92 2 Calum 1 82 5 Scott 2 94 2 Jason 3 55 8 Glenn 4 82 2 Fergus 5
Sample Output :
TESTCASE 01
78.00
TESTCASE 02
81.00
Explanation :
TESTCASE 01
Average = (97 + 50 + 91 + 72 + 80)/5
Can you solve this challenge in 4 lines of code or less?NOTE: There is no penalty for solutions that are correct but have more than 4 lines.
Collections.namedtuple() in Python – HackerRank Solution
# Collections.namedtuple() in Python - Hacker Rank Solution # Python 3 # Enter your code here. Read input from STDIN. Print output to STDOUT # Collections.namedtuple() in Python - Hacker Rank Solution START import collections n = int(input()) scol = ','.join(input().split()) Student = collections.namedtuple('Student',scol) sum = 0 for i in range(n): row = input().split() student = Student(*row) sum += int(student.MARKS) print(sum/n)