From c65abc89f3bb9ea77a7f6c566d0622bd4faacf55 Mon Sep 17 00:00:00 2001 From: vivekshingate Date: Sat, 1 Sep 2018 17:48:47 +0000 Subject: [PATCH 1/7] Done --- q01_read_data/build.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/q01_read_data/build.py b/q01_read_data/build.py index e13d2f74..8873c032 100644 --- a/q01_read_data/build.py +++ b/q01_read_data/build.py @@ -1,12 +1,19 @@ +# %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 = - + + #with open('./data/ipl_match.yaml','r') as yaml_file_read: + yaml_file_read = open('./data/ipl_match.yaml','r') + data = yaml.load(yaml_file_read) + # return data variable return data + +read_data() + + From 72ef56ec28e766f1d1770aa153da939f672a7673 Mon Sep 17 00:00:00 2001 From: vivekshingate Date: Sat, 1 Sep 2018 18:16:18 +0000 Subject: [PATCH 2/7] Done --- q02_teams/build.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/q02_teams/build.py b/q02_teams/build.py index 3cf9d3cf..90207d92 100644 --- a/q02_teams/build.py +++ b/q02_teams/build.py @@ -1,11 +1,21 @@ +# %load q02_teams/build.py # default imports from greyatomlib.python_getting_started.q01_read_data.build import read_data data = read_data() +#data.keys() +#data['info']['teams'] +#a['teams'] + # solution -def teams(data=data): +def teams(data): # write your code here - #teams = + teams = data['info']['teams'] return teams + + + + + From f29ddd7eb5117472fc9568cc8757b32295ba25db Mon Sep 17 00:00:00 2001 From: vivekshingate Date: Sat, 1 Sep 2018 18:37:49 +0000 Subject: [PATCH 3/7] Done --- q03_first_batsman/build.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/q03_first_batsman/build.py b/q03_first_batsman/build.py index 84984081..36e9a36c 100644 --- a/q03_first_batsman/build.py +++ b/q03_first_batsman/build.py @@ -2,12 +2,15 @@ from greyatomlib.python_getting_started.q01_read_data.build import read_data data = read_data() +#a=data['innings'][0]['1st innings']['deliveries'][0][0.1]['batsman'] +#a + # Your Solution def first_batsman(data=data): # Write your code here + name = data['innings'][0]['1st innings']['deliveries'][0][0.1]['batsman'] + return name - - return name From 9c60f4d42c58b66df3c5bb21305d9f3c7daac4cf Mon Sep 17 00:00:00 2001 From: vivekshingate Date: Sun, 2 Sep 2018 16:13:00 +0000 Subject: [PATCH 4/7] Done --- q04_count/build.py | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/q04_count/build.py b/q04_count/build.py index 6cf3dcbc..cc0ee626 100644 --- a/q04_count/build.py +++ b/q04_count/build.py @@ -1,11 +1,41 @@ # Default Imports from greyatomlib.python_getting_started.q01_read_data.build import read_data data = read_data() +# dict lst dict dict v_lst v_dict dict +#x=data['innings'][0]['1st innings']['deliveries'][0]['0.1']['batsman'] +x=data['innings'][0]['1st innings']['deliveries'] +#print(type(x)) +#print(x) + # Your Solution Here -def deliveries_count(data=data): +def deliveries_count(data): # Your code here + count=0 + + for i,v in enumerate(x): + y=x[i] + #print(type(y)) + for k,v in y.items(): + if y[k]['batsman']=='RT Ponting': + count += 1 + + return count + +deliveries_count(data) + + + + + + + + + + + + From fda762b6b6917111900b7678e4bf4a7790b45511 Mon Sep 17 00:00:00 2001 From: vivekshingate Date: Sun, 2 Sep 2018 18:31:23 +0000 Subject: [PATCH 5/7] Done --- q05_runs/build.py | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/q05_runs/build.py b/q05_runs/build.py index a250631a..6d8d5547 100644 --- a/q05_runs/build.py +++ b/q05_runs/build.py @@ -1,12 +1,41 @@ +# %load q05_runs/build.py # Default Imports from greyatomlib.python_getting_started.q01_read_data.build import read_data data = read_data() - # Your Solution def BC_runs(data): # Write your code here + + #Defining variable 'a'. This will store the content of 1st innings delivery wise + a=data['innings'][0]['1st innings']['deliveries'] + + #initialising variable runs = 0 + runs = 0 + + #to check the type of next key/index. Accordingly use .key() or index to access the event drilling down in the .yaml file. + print(type(a)) + + #For dicts - To see next level keys while drilling down in the list. + #print(a.keys()) + + #For lists - To access next level index, values while drilling down in the list. + #for i,v in enumerate(a): + # if i<=9: + # print(i,v) + + #Each delivery is stored in a separate index. So for loop to iterate thru the deliveries. + for i,v in enumerate(a): + for k,v in a[i].items(): #To loop thru each delivery viz. 0.1, 0.2 etc in dicts. + #print(a[i][k]['batsman']) #Print batsman name for test purpose + #print(a[i][k]['runs']['batsman']) #Print runs scored by above batsman on each delivery. + if a[i][k]['batsman'] == 'BB McCullum': #Narrowing down on BB McCullum + runs += a[i][k]['runs']['batsman'] #Storing runs scored by BB McCullum in runs variable. + return(runs) + +BC_runs(data) + + - return(runs) From c3459f15f2a6ef761b12cab3baee20e3b4d65924 Mon Sep 17 00:00:00 2001 From: vivekshingate Date: Mon, 3 Sep 2018 05:49:02 +0000 Subject: [PATCH 6/7] Done --- q06_bowled_players/build.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/q06_bowled_players/build.py b/q06_bowled_players/build.py index 914cb6d2..17a1d5df 100644 --- a/q06_bowled_players/build.py +++ b/q06_bowled_players/build.py @@ -1,11 +1,28 @@ +# %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): +def bowled_out(data): + + #assign a with avlues of data which would remain static throughout the problem statement + a = data['innings'][1]['2nd innings']['deliveries']#[7][1.1]['wicket']['kind'] #For testing to access subsequent element. + #print(type(a)) + #print(a) + bowled_players=[] #To store return data + + for i,v in enumerate(a): #looping thru deliveries + for k,v in a[i].items(): #looping thru deliveries viz. 0.1, 0.2 etc. + if 'wicket' in a[i][k].keys(): #narrowing down in dicts which have 'wicket' as key. + if 'bowled' in a[i][k]['wicket']['kind']: #further filtering to narrow dewn on 'bowled' as kind of wicket. + #print(a[i][k]['wicket']['kind'],' ',a[i][k]['wicket']['player_out']) # just to check the player names who were bowled out. + bowled_players.append(a[i][k]['wicket']['player_out']) + + return bowled_players + + +bowled_out(data) - # Write your code here - return bowled_players From 9d8f190d8a91d999f1d870d5f2448952b19af968 Mon Sep 17 00:00:00 2001 From: vivekshingate Date: Mon, 3 Sep 2018 18:31:55 +0000 Subject: [PATCH 7/7] Done --- q07_extras/build.py | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/q07_extras/build.py b/q07_extras/build.py index cdeb803b..d1f8867c 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,32 @@ def extras_runs(data=data): # Write your code here + + a = data['innings'][0]['1st innings']['deliveries'] + b = data['innings'][1]['2nd innings']['deliveries'] + + extra_1st_inn = [] + extra_2nd_inn = [] + #For 1st innings + for i,v in enumerate(a): #Tracking delivery by delivery elemnt of list viz. [0],[1],[2] etc. + for k,v in a[i].items(): #Going inside each delivery viz. 0.1, 0.2 etc. + if 'extras' in a[i][k].keys(): #if there's an 'extra' key in the delivery go inside it and get its value. + for key,val in a[i][k]['extras'].items(): + print(a[i][k]['extras'][key]) + extra_1st_inn.append(a[i][k]['extras'][key]) - difference = - + #For second innings (logic same as 1st innings) + for i,v in enumerate(b): + for k,v in b[i].items(): + if 'extras' in b[i][k].keys(): + for key,val in b[i][k]['extras'].items(): + print(b[i][k]['extras'][key]) + extra_2nd_inn.append(b[i][k]['extras'][key]) + difference = len(extra_2nd_inn) - len(extra_1st_inn) + return difference + + +