From 2be675990f035f1d6d4691aa8bb3bcd9fade4bc8 Mon Sep 17 00:00:00 2001 From: paragDC Date: Fri, 7 Sep 2018 14:56:21 +0000 Subject: [PATCH 1/7] Done --- q01_read_data/build.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/q01_read_data/build.py b/q01_read_data/build.py index e13d2f74..6e131d2d 100644 --- a/q01_read_data/build.py +++ b/q01_read_data/build.py @@ -1,12 +1,12 @@ 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 stream: + data = yaml.load(stream) # return data variable return data + + From 5132f05c35b5579e8cd71afa0264ab6521f0d250 Mon Sep 17 00:00:00 2001 From: paragDC Date: Fri, 7 Sep 2018 15:03:01 +0000 Subject: [PATCH 2/7] Done --- q02_teams/build.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/q02_teams/build.py b/q02_teams/build.py index 3cf9d3cf..3f876670 100644 --- a/q02_teams/build.py +++ b/q02_teams/build.py @@ -1,11 +1,11 @@ -# default imports -from greyatomlib.python_getting_started.q01_read_data.build import read_data -data = read_data() +import yaml +def teams(data): + info = data['info'] + team = info['teams'] + return team -# solution -def teams(data=data): +with open('data/ipl_match.yaml','r') as stream: + data = yaml.load(stream) + +teams(data) - # write your code here - #teams = - - return teams From ba6471bd5cdefbf57b87a9cdd068d45e441ac154 Mon Sep 17 00:00:00 2001 From: paragDC Date: Fri, 7 Sep 2018 15:12:00 +0000 Subject: [PATCH 3/7] Done --- q03_first_batsman/build.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/q03_first_batsman/build.py b/q03_first_batsman/build.py index 84984081..09a178ed 100644 --- a/q03_first_batsman/build.py +++ b/q03_first_batsman/build.py @@ -1,13 +1,11 @@ +# %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): - - # Write your code here - - + name = batsman_name = data['innings'][0].get('1st innings').get('deliveries')[0].get(0.1).get('batsman') + return name - return name From 85c780f810c5b10b64f722ce9f3e70396d0a4099 Mon Sep 17 00:00:00 2001 From: paragDC Date: Fri, 7 Sep 2018 17:10:39 +0000 Subject: [PATCH 4/7] Done --- q04_count/build.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/q04_count/build.py b/q04_count/build.py index 6cf3dcbc..09555f71 100644 --- a/q04_count/build.py +++ b/q04_count/build.py @@ -1,11 +1,18 @@ +# %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): - - # Your code here - - + count = 0 + first_innings = data['innings'][0].get('1st innings').get('deliveries') + count = 0 + for x in range(0,len(first_innings)): + delivery = first_innings[x] + for key in delivery: + if delivery[key].get('batsman') == 'RT Ponting': + count = count+1 return count + From 2f007730cafb1af2ac9b3976eb85bbf1a2fc671b Mon Sep 17 00:00:00 2001 From: paragDC Date: Fri, 7 Sep 2018 17:12:50 +0000 Subject: [PATCH 5/7] Done --- q05_runs/build.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/q05_runs/build.py b/q05_runs/build.py index a250631a..63207018 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,13 @@ # Your Solution def BC_runs(data): + first_innings = data['innings'][0].get('1st innings').get('deliveries') + count = 0 + runs = 0 + for x in range(0,len(first_innings)): + delivery = first_innings[x] + for key in delivery: + if delivery[key].get('batsman') == 'BB McCullum': + runs = runs + delivery[key].get('runs').get('batsman') + return runs - # Write your code here - - - return(runs) From f564be53d9d7759830574b69f3cd0da657f60144 Mon Sep 17 00:00:00 2001 From: paragDC Date: Fri, 7 Sep 2018 17:15:29 +0000 Subject: [PATCH 6/7] Done --- q06_bowled_players/build.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/q06_bowled_players/build.py b/q06_bowled_players/build.py index 914cb6d2..7158dd75 100644 --- a/q06_bowled_players/build.py +++ b/q06_bowled_players/build.py @@ -1,11 +1,21 @@ +# %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): - - # Write your code here - - + second_innings = data['innings'][1].get('2nd innings').get('deliveries') + bowled_players = [] + + for x in range(0,len(second_innings)): + delivery = second_innings[x] + + for key in delivery: + if delivery[key].get('wicket') != None: + + if delivery[key].get('wicket').get('kind') == 'bowled': + bowled_players.append(delivery[key].get('batsman')) + return bowled_players + From 5b3f31abb1ec3adfaca1bdbcb10b4d86acd72ebd Mon Sep 17 00:00:00 2001 From: paragDC Date: Fri, 7 Sep 2018 17:17:53 +0000 Subject: [PATCH 7/7] Done --- q07_extras/build.py | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/q07_extras/build.py b/q07_extras/build.py index cdeb803b..5b647d85 100644 --- a/q07_extras/build.py +++ b/q07_extras/build.py @@ -1,14 +1,32 @@ +# %load q07_extras/build.py # Default Imports from greyatomlib.python_getting_started.q01_read_data.build import read_data data = read_data() # Your Solution def extras_runs(data=data): - # Write your code here - - - difference = - - + st_innis = data.get('innings')[0].get('1st innings').get('deliveries') + nd_innis = data.get('innings')[1].get('2nd innings').get('deliveries') + + extras_in_st_inngs = [] + extras_in_nd_inngs = [] + + for x in range(0,len(st_innis)): + current_delivery = st_innis[x] + for key in current_delivery: + extras_per_delivery = current_delivery.get(key).get('runs').get('extras') + if extras_per_delivery != 0: + extras_in_st_inngs.append(extras_per_delivery) + + + for x in range(0,len(nd_innis)): + current_delivery = nd_innis[x] + for key in current_delivery: + extras_per_delivery = current_delivery.get(key).get('runs').get('extras') + if extras_per_delivery != 0: + extras_in_nd_inngs.append(extras_per_delivery) + + difference = len(extras_in_nd_inngs)-len(extras_in_st_inngs) return difference +