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 $\textit{IDs}$, $marks$, $class$ and $name$.  

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

$\textit{Average}=\dfrac{\textit{Sum of all marks}}{\textit{Total 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$, $\textit{IDs}$, $name$ and $class$, under their respective column names.

Constraints

$0<N\leq100$

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.

Difficulty: EASY

Solutions:
(N, m, avg) = (int(input()), input().split().index('MARKS'), 0)
for i in range(N):
	avg += float(input().split()[m])
print('{0:.2f}'.format(avg / N))


N = int(input())
pos = input().split().index('MARKS')
sums = list()
for _ in range(N):
	sums.append(int(input().split()[pos]))
print('%.2f' % (sum(sums) / len(sums)))


from collections import namedtuple
from functools import reduce
size = int(input())
rs = []
record = namedtuple('record', input())
for _ in range(0, size):
	rs.append(record(*list(input().split())))
s = reduce(lambda x, y: x + y, [float(row.MARKS) for row in rs])
print('{0:.2f}'.format(s / size))


from collections import namedtuple
N = int(input())
Student = namedtuple('Student', input())
print('%.2f' % (sum((int(Student(*input().split()).MARKS) for _ in range(N))) / N))


import collections, statistics
N = int(input())
Student = collections.namedtuple('Student', input().split())
print('{0:.2f}'.format(statistics.mean(map(lambda student: float(student.MARKS), [Student._make(input().split()) for _ in range(N)]))))


(nips, ip, avg) = (int(input()), list(map(str, input().split())), 0)
for i in range(0, nips):
	avg = avg + int(list(map(str, input().split()))[ip.index('MARKS')])
print('{0:.2f}'.format(round(avg / nips, 2)))


N = int(input())
columns = list(input().split())
sum = 0
for n in range(N):
	sum += int(input().split()[columns.index('MARKS')])
print('{:.2f}'.format(sum / N))


from collections import namedtuple
x = int(input())
stu = namedtuple('Student', input())
s = 0
for i in range(0, x):
	inp = input().split()
	tu = stu(inp[0], inp[1], inp[2], inp[3])
	s += int(tu.MARKS)
print('%.2f' % (s / x))


x = int(input())
L = input().split()
Students = []
marks = L.index('MARKS')
for _ in range(x):
	Student = input().split()
	Students.append(int(Student[marks]))
print('{:.2f}'.format(sum(Students) / x))


from collections import namedtuple
N = int(input())
Student = namedtuple('Student', input())
m = 0
for i in range(N):
	m += int(Student(*input().split()).MARKS)
print('{:.2f}'.format(m / N))


from collections import namedtuple
n = int(input())
p = input()
data = namedtuple('Lole', p)
avg = 0
for i in range(n):
	lol = input().split()
	lel = data(lol[0], lol[1], lol[2], lol[3])
	avg += int(lel.MARKS) / float(n)
print(format(avg, '0.2f'))


from collections import namedtuple

def create_array(text):
	columns_names = list(text.replace(' ', ',').split(','))
	columns_names = [x for x in columns_names if x != '' and x != '\r']
	return columns_names
x = int(input())
columns_names = create_array(input())
marks_sum = 0
Student = namedtuple('Student', columns_names[0] + ' ' + columns_names[1] + ' ' + columns_names[2] + ' ' + columns_names[3])
for i in range(x):
	data = create_array(input())
	student = Student(data[0], data[1], data[2], data[3])
	marks_sum += int(student.MARKS)
print('%.2f' % float(marks_sum / x))


from collections import namedtuple
n = int(input())
Record = namedtuple('Record', input().split())
records = [Record(*input().split()) for _ in range(n)]
print('{:.2f}'.format(sum([int(x.MARKS) for x in records]) / n))


from collections import namedtuple
students = int(input())
Student = namedtuple('Student', 'ID, MARKS, CLASS, NAME')
s = 0
columns = input().split()
for each in range(students):
	row = input().split()
	for j in range(4):
		if columns[j] == 'ID':
			id = row[j]
		elif columns[j] == 'MARKS':
			mark = row[j]
		elif columns[j] == 'CLASS':
			classname = row[j]
		elif columns[j] == 'NAME':
			name = row[j]
	stdnt = Student(ID=id, MARKS=mark, CLASS=classname, NAME=name)
	s += int(stdnt.MARKS)
print('{0:.2f}'.format(s / students))


from collections import namedtuple
n = int(input())
headers = input().split()
Marks = namedtuple('Marks', headers)
s = []
for i in range(n):
	m = Marks._make(input().split())
	s.append(m)
print('{0:.2f}'.format(sum([int(e.MARKS) for e in s]) / n))


from collections import namedtuple
n = int(input())
Grade = namedtuple('Grade', ','.join(input().split()))
print('{:.2f}'.format(sum([int(Grade(*input().split()).MARKS) for _ in range(n)]) / n))


def main():
	import collections, statistics
	N = int(input())
	Student = collections.namedtuple('Student', input().split())
	print('{0:.2f}'.format(statistics.mean(map(lambda student: float(student.MARKS), [Student._make(input().split()) for _ in range(N)]))))
main()


from collections import namedtuple
n = int(input())
Type = namedtuple('Type', input().split())
s = 0
for _ in range(n):
	data = Type(*input().split())
	s += int(data.MARKS)
print('{:.2f}'.format(s / n))


from collections import namedtuple
n = int(input())
(c1, c2, c3, c4) = input().split()
Student = namedtuple('Student', '{}, {}, {}, {}'.format(c1, c2, c3, c4))
marks = []
for _ in range(n):
	(d1, d2, d3, d4) = input().split()
	s = Student(d1, d2, d3, d4)
	marks.append(int(s.MARKS))
print('{:.2f}'.format(sum(marks) / len(marks)))


from collections import namedtuple
n = int(input())
Student = namedtuple('Student', input().split())
l = [Student._make(input().split()) for _ in range(n)]
print('{0:0.2f}'.format(round(sum([float(s.MARKS) for s in l]) / n, 2)))


from collections import namedtuple
N = int(input())
sum = 0
Student = namedtuple('Student', input().split())
for i in range(N):
	stdnt = Student._make(input().split())
	sum = sum + int(stdnt.MARKS)
print('{0:.2f}'.format(sum / N))


from collections import namedtuple
n = int(input())
marks = namedtuple('marks', input().split())
print('{:.2f}'.format(sum(map(int, (marks(*input().split()).MARKS for _ in range(n)))) / n))


(n, i) = (int(input()), input().split().index('MARKS'))
print('%.2f' % (sum([int(input().split()[i]) for _ in range(n)]) / n))


n = int(input())
ind = input().strip().split().index('MARKS')
print('{:.2f}'.format(sum(map(int, [input().strip().split()[ind] for _ in range(n)])) / n))


from collections import namedtuple
(n, cn) = (int(input()), input().split())
Data = namedtuple('Data', ' '.join(cn))
print('%.2f' % (sum([int(Data(*input().split()).MARKS) for _ in range(n)]) / n))


from collections import namedtuple
N = int(input())
student = namedtuple('student', ' '.join(input().split()))
students = [student(*input().split()) for x in range(N)]
print('{0:.2f}'.format(sum([float(s.MARKS) for s in students]) / len(students)))


from collections import namedtuple
n = int(input())
Student = namedtuple('Student', input())
total = 0
for i in range(n):
	std = input().split()
	s = Student(std[0], std[1], std[2], std[3])
	total += int(s.MARKS)
print('{0:.2f}'.format(total / n))


N = int(input())
index = input().split().index('MARKS')
scores = [int(input().split()[index]) for _ in range(N)]
print('%.2f' % (sum(scores) / N))


from collections import namedtuple
nr_lines = int(input())
Student = namedtuple('Student', input())
sum_ = 0
for i in range(nr_lines):
	student = Student(*input().split())
	sum_ += int(student.MARKS)
print('{:.2f}'.format(sum_ / nr_lines))


from collections import namedtuple
n = int(input())
names = input().split()
m = -1
for i in range(4):
	if names[i] == 'MARKS':
		m = i
sum = 0
for i in range(n):
	str = input().split()
	sum += int(str[m])
print('%.2f' % (sum / n))


from collections import namedtuple
(n, columns) = (int(input()), input())
c = namedtuple('Column', columns)(0, 1, 2, 3)
print('{:.2f}'.format(sum([int(input().split()[c.MARKS]) for _ in range(n)]) / float(n)))


n = int(input())
s = input().split()
if s[0] == 'MARKS':
	index = 0
elif s[1] == 'MARKS':
	index = 1
elif s[2] == 'MARKS':
	index = 2
else:
	index = 3
sum = 0
for i in range(n):
	s = input().split()
	sum += float(s[index])
sum = sum / (i + 1)
print('{0:.2f}'.format(sum))