Top three scorers

EasyCollections Programs · 18 of 20

Write a Python program to total player runs from match records and show the top 3.

Advertisement
Output
[('Virat', 143), ('Rohit', 115), ('Gill', 90)]

Approach

  1. Add runs into a Counter.

Solution

Python
from collections import Counter innings = [("Virat", 82), ("Rohit", 45), ("Virat", 61), ("Gill", 90), ("Rohit", 70), ("Rahul", 30)]totals = Counter()for player, runs in innings:    totals[player] += runsprint(totals.most_common(3))
Output
[('Virat', 143), ('Rohit', 115), ('Gill', 90)]

Learn the concept

New to this topic? Read the lesson, then come back.

More collections programs

← All 20 Collections Programs

Leave a Comment