Skip to content

Commit ae21035

Browse files
authored
updated using current hackerrank stab
1 parent e2b21a5 commit ae21035

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

Collections/Collectionsnamedtuple.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@
44
Domain : Python
55
Author : Ahmedur Rahman Shovon
66
Created : 15 July 2016
7+
Updated : 09 February 2023
78
Problem : https://www.hackerrank.com/challenges/py-collections-namedtuple/problem
89
"""
910

10-
n = int(input())
11-
col_list = list(input().split())
12-
marks_col = col_list.index("MARKS")
13-
marks_list = []
14-
for _ in range(n):
15-
info_list = list(input().split())
16-
marks_list.append(float(info_list[marks_col]))
17-
print(sum(marks_list) / n)
11+
from collections import namedtuple
12+
n=int(input())
13+
columns = ",".join(input().split())
14+
Student = namedtuple("Student", columns)
15+
data = []
16+
for i in range(n):
17+
row = input().split()
18+
s = Student._make(row)
19+
data.append(s)
20+
avg = sum(float(s.MARKS) for s in data) / n
21+
print(f"{avg:.2f}")

0 commit comments

Comments
 (0)