diff --git a/q01_read_data/build.py b/q01_read_data/build.py index e13d2f74..2e7b27fb 100644 --- a/q01_read_data/build.py +++ b/q01_read_data/build.py @@ -1,12 +1,15 @@ +# %load q01_read_data/build.py import yaml - def read_data(): - # import the csv file into `data` variable + # import the csv file into variable # You can use this path to access the CSV file: '../data/ipl_match.yaml' # Write your code here - - data = + + data = yaml.safe_load(open('./data/ipl_match.yaml')) # return data variable return data + +read_data() + diff --git a/q02_teams/build.py b/q02_teams/build.py index 3cf9d3cf..5380d68a 100644 --- a/q02_teams/build.py +++ b/q02_teams/build.py @@ -1,11 +1,17 @@ +# %load q02_teams/build.py # default imports from greyatomlib.python_getting_started.q01_read_data.build import read_data data = read_data() # solution -def teams(data=data): +lst = [] +def teams(data): + lst.append(data['info']['teams']) # write your code here - #teams = + + return lst[0] + +teams(data) +lst[0] - return teams diff --git a/q03_first_batsman/build.py b/q03_first_batsman/build.py index 84984081..b42e60f3 100644 --- a/q03_first_batsman/build.py +++ b/q03_first_batsman/build.py @@ -1,13 +1,16 @@ +# %load q03_first_batsman/build.py # Default Imports from greyatomlib.python_getting_started.q01_read_data.build import read_data data = read_data() # Your Solution def first_batsman(data=data): + name=data['innings'][0]['1st innings']['deliveries'][0][0.1]['batsman'] # Write your code here - return name +first_batsman(data) + diff --git a/q04_count/build.py b/q04_count/build.py index 6cf3dcbc..ab7859b7 100644 --- a/q04_count/build.py +++ b/q04_count/build.py @@ -1,11 +1,29 @@ +# %load q04_count/build.py # Default Imports from greyatomlib.python_getting_started.q01_read_data.build import read_data data = read_data() # Your Solution Here + def deliveries_count(data=data): + count=0 + deliveries = data['innings'][0]['1st innings']['deliveries'] + b = 0.1 + for a in range(len(deliveries)): + for b in deliveries[a]: + print(deliveries[a][b]['batsman']) + if (deliveries[a][b]['batsman']=='RT Ponting'): + count+=1 + return count + + # Your code here + +deliveries_count(data) +#lst[0][46][7.3]['batsman'] +#list(range(lst[0][1],lst[0][123])) +#data['innings'][0]['1st innings']['deliveries'] +current_deliveries - return count diff --git a/q05_runs/build.py b/q05_runs/build.py index a250631a..ef4affc8 100644 --- a/q05_runs/build.py +++ b/q05_runs/build.py @@ -1,3 +1,4 @@ +# %load q05_runs/build.py # Default Imports from greyatomlib.python_getting_started.q01_read_data.build import read_data data = read_data() @@ -5,8 +6,16 @@ # Your Solution def BC_runs(data): - + # Write your code here - + runs=0 + data1=data['innings'][0]['1st innings']['deliveries'] + for i in data1: + data2=list(i.values()) + if data2[0]['batsman']=='BB McCullum': + if data2[0]['runs']['batsman']>0: + runs=runs+data2[0]['runs']['batsman'] return(runs) +BC_runs(data) + diff --git a/q06_bowled_players/build.py b/q06_bowled_players/build.py index 914cb6d2..66f89877 100644 --- a/q06_bowled_players/build.py +++ b/q06_bowled_players/build.py @@ -1,11 +1,23 @@ +# %load q06_bowled_players/build.py # Default Imports from greyatomlib.python_getting_started.q01_read_data.build import read_data data = read_data() # Your Solution def bowled_out(data=data): - + bowled_players = [] # Write your code here + delivery = data['innings'][1]['2nd innings']['deliveries'] + for balls in delivery: + data1 = list(balls.values()) + if 'wicket' in data1[0].keys(): + if data1[0]['wicket']['kind']=='bowled': + bowled_players.append(data1[0]['batsman']) + return bowled_players + +bowled_out(data) + + + - return bowled_players