Filter countries Sachin has played against

Filter countries Sachin has played against

OneDayInternational.csv is a csv file containing nearly 200 records on Sachin’s ODIs from 1990 to 1998.  Read this CSV file using DictReader() and filter the countries he has played against, order them alphabetically and display !

Here is the sample of first 2 records from OneDayInternational.csv

Country    Player                             Runs      ScoreRate         MatchDate     Ground                   Versus    URL
Ind             Sachin R Tendulkar    0             0                          1/3/1990         Carisbrook            NZ            673
Ind             Sachin R Tendulkar    36          92.30769231   6/3/1990         Basin Reserve     NZ            676

Code :-

import csv
reader=csv.DictReader(open('OneDayInternational.csv','r'))
countries=[]
for row_no,line in enumerate(reader):
    if not line['Versus'] in countries:
        countries.append(line['Versus'])
x=sorted(countries)
for i in x:
    print(i)

    

Leave a Comment

Your email address will not be published. Required fields are marked *

x