diff --git a/q01_read_data/build.py b/q01_read_data/build.py index e13d2f74..3f249342 100644 --- a/q01_read_data/build.py +++ b/q01_read_data/build.py @@ -1,12 +1,18 @@ +# %load q01_read_data/build.py import yaml def read_data(): - - # import the csv file into `data` variable - # You can use this path to access the CSV file: '../data/ipl_match.yaml' - # Write your code here - - data = + file_path= './data/ipl_match.yaml' + with open(file_path, 'r') as f: + data = yaml.load(f) # return data variable return data + + + + + + + + diff --git a/q02_teams/build.py b/q02_teams/build.py index 3cf9d3cf..665c8d66 100644 --- a/q02_teams/build.py +++ b/q02_teams/build.py @@ -1,11 +1,24 @@ +# %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): +def teams(data = data): + y=list(data['info']['teams']) + return y + +#f_list=list(data.values(['info'] ['teams'])) +#print(f_list) +#print (x) + + +teams() + + + + + + - # write your code here - #teams = - return teams diff --git a/q03_first_batsman/build.py b/q03_first_batsman/build.py index 84984081..d3b2d91a 100644 --- a/q03_first_batsman/build.py +++ b/q03_first_batsman/build.py @@ -1,13 +1,15 @@ +# %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 + # Write your code here def first_batsman(data=data): + x=data['innings'][0]['1st innings']['deliveries'][0][0.1]['batsman'] + return x - # Write your code here +first_batsman() + # return name - return name diff --git a/q04_count/build.py b/q04_count/build.py index 6cf3dcbc..65207500 100644 --- a/q04_count/build.py +++ b/q04_count/build.py @@ -1,3 +1,4 @@ +# %load q04_count/build.py # Default Imports from greyatomlib.python_getting_started.q01_read_data.build import read_data data = read_data() @@ -6,6 +7,15 @@ def deliveries_count(data=data): # Your code here - - + total_balls = len(data['innings'][0]['1st innings']['deliveries']) + count = 0 + for i in range(0,total_balls): + key = next(iter(data['innings'][0]['1st innings']['deliveries'][i])) + if data['innings'][0]['1st innings']['deliveries'][i][key]['batsman']=='RT Ponting': + count = count+1 return count + +deliveries_count(data=data) + + + diff --git a/q05_runs/build.py b/q05_runs/build.py index a250631a..52225a21 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,18 @@ # Your Solution def BC_runs(data): + total_balls = len(data['innings'][0]['1st innings']['deliveries']) + runs = 0 + for i in range(0,total_balls): + + key = next(iter(data['innings'][0]['1st innings']['deliveries'][i])) + + if data['innings'][0]['1st innings']['deliveries'][i][key]['batsman']=='BB McCullum': + runs = runs + data['innings'][0]['1st innings']['deliveries'][i][key]['runs']['batsman'] + + return runs + +BC_runs(data) - # Write your code here - return(runs)