LearnPy Hub
← File Handling problems
Hard

Join Two CSV Files

Read students id,name until END and write them to students.csv; then read marks id,subject,mark until END and write them to marks.csv. Read both files with csv.reader, join them on id, and write report.csv with a header name,subjects,average: one row per student in id order, with the number of subjects and the average mark (1 decimal, or - if none). Print report.csv.

Input

Two blocks of lines, each ending with END.

Output

Lines.

Sample 1

Input
2,Rafi
1,Mim
3,Sara
END
1,math,80
2,math,70
1,bangla,91
END
Output
name,subjects,average
Mim,2,85.5
Rafi,1,70.0
Sara,0,-

Sample 2

Input
1,A
END
1,x,5
END
Output
name,subjects,average
A,1,5.0
solution.py
Output appears here
Join Two CSV Files · Python practice problem · LearnPy Hub