diff --git a/q01_read_data/build.py b/q01_read_data/build.py index e13d2f74..c05e75cf 100644 --- a/q01_read_data/build.py +++ b/q01_read_data/build.py @@ -1,12 +1,16 @@ +# %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.load(open('./data/ipl_match.yaml')) # return data variable return data + + + diff --git a/q02_teams/build.py b/q02_teams/build.py index 3cf9d3cf..5634db0b 100644 --- a/q02_teams/build.py +++ b/q02_teams/build.py @@ -1,3 +1,4 @@ +# %load q02_teams/build.py # default imports from greyatomlib.python_getting_started.q01_read_data.build import read_data data = read_data() @@ -6,6 +7,10 @@ def teams(data=data): # write your code here - #teams = + teams = data['info']['teams'] return teams +T = teams() +T + + diff --git a/q03_first_batsman/build.py b/q03_first_batsman/build.py index 84984081..6490c0e6 100644 --- a/q03_first_batsman/build.py +++ b/q03_first_batsman/build.py @@ -1,3 +1,4 @@ +# %load q03_first_batsman/build.py # Default Imports from greyatomlib.python_getting_started.q01_read_data.build import read_data data = read_data() @@ -6,8 +7,11 @@ def first_batsman(data=data): # Write your code here + name = data['innings'][0]['1st innings'] ['deliveries'] [0][0.1] ['batsman'] + return name +name = first_batsman() +name - return name diff --git a/q04_count/build.py b/q04_count/build.py index 6cf3dcbc..8f867cba 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,16 @@ def deliveries_count(data=data): # Your code here + count = 0 - + p=data['innings'][0]['1st innings']['deliveries'] + for a in p: + for b in a: + if (a[b]['batsman'])=='RT Ponting': + count=count+1 + return count + +deliveries_count(data) + + diff --git a/q05_runs/build.py b/q05_runs/build.py index a250631a..53549adb 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() @@ -7,6 +8,13 @@ def BC_runs(data): # Write your code here + runs = 0 + p = data['innings'][0]['1st innings']['deliveries'] + for a in p: + for b in a: + if (a[b]['batsman'])=='BB McCullum': + runs += (a[b]['runs']['batsman']) + return(runs) +BC_runs(data) - return(runs) diff --git a/q06_bowled_players/build.py b/q06_bowled_players/build.py index 914cb6d2..aa5edf1e 100644 --- a/q06_bowled_players/build.py +++ b/q06_bowled_players/build.py @@ -1,11 +1,24 @@ +# %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 +bowled_players = [] def bowled_out(data=data): # Write your code here + bowled_players = [] + for delivery in data['innings'][1]['2nd innings']['deliveries']: + + if(delivery[next(iter(delivery))].get('wicket', {}).get('kind', None) == 'bowled'): + + bowled_players.append(delivery[next(iter(delivery))]['batsman']) return bowled_players + +ao = bowled_out() +ao + + diff --git a/q07_extras/build.py b/q07_extras/build.py index cdeb803b..920167e7 100644 --- a/q07_extras/build.py +++ b/q07_extras/build.py @@ -1,3 +1,4 @@ +# %load q07_extras/build.py # Default Imports from greyatomlib.python_getting_started.q01_read_data.build import read_data data = read_data() @@ -6,9 +7,75 @@ def extras_runs(data=data): # Write your code here + + l=(data['innings'][0]['1st innings']['deliveries']) + E1=[0,0,0] + x=0 + for a in l: + for b in a: + if 'extras' in a[b].keys(): + x+=1 + if 'wides' in a[b]['extras'].keys(): + E1[0]+=1 + elif 'legbyes' in a[b]['extras'].keys(): + E1[1]+=1 + else: + E1[2]+=1 + + l2=(data['innings'][1]['2nd innings']['deliveries']) + E1=[0,0,0] + y=0 + for a in l2: + for b in a: + if 'extras' in a[b].keys(): + y+=1 + if 'wides' in a[b]['extras'].keys(): + E1[0]+=1 - difference = + elif 'legbyes' in a[b]['extras'].keys(): + E1[1]+=1 + else: + E1[2]+=1 + difference = y-x return difference + +l2=(data['innings'][1]['2nd innings']['deliveries']) +E1=[0,0,0] +x=0 +for a in l2: + for b in a: + if 'extras' in a[b].keys(): + x+=1 + if 'wides' in a[b]['extras'].keys(): + E1[0]+=1 + + elif 'legbyes' in a[b]['extras'].keys(): + E1[1]+=1 + else: + E1[2]+=1 +print(E1) +print(x) +(data['innings'][1]['2nd innings']['deliveries'][1][0.2]['extras']) + +l2=(data['innings'][0]['1st innings']['deliveries']) +E1=[0,0,0] +x=0 +for a in l2: + for b in a: + if 'extras' in a[b].keys(): + x+=1 + if 'wides' in a[b]['extras'].keys(): + E1[0]+=1 + + elif 'legbyes' in a[b]['extras'].keys(): + E1[1]+=1 + else: + E1[2]+=1 + +h = extras_runs() +h + +