From 00ce8b701fdac390dc13c936fbe82a81418a5deb Mon Sep 17 00:00:00 2001 From: tracedence Date: Sat, 8 Sep 2018 09:03:25 +0000 Subject: [PATCH 1/7] Done --- q01_read_data/build.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/q01_read_data/build.py b/q01_read_data/build.py index e13d2f74..83e84cc3 100644 --- a/q01_read_data/build.py +++ b/q01_read_data/build.py @@ -1,12 +1,23 @@ +# %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' + # import the csv file into variable + #ta 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 file_obj: + data = yaml.load(file_obj) # to load content of file + #print(type(data)) + print(data) + # return data variable return data +read_data() + + + + + + From b7a26c261b2fb758196cdca7a2de388bbb65dec0 Mon Sep 17 00:00:00 2001 From: tracedence Date: Sat, 8 Sep 2018 09:07:38 +0000 Subject: [PATCH 2/7] Done --- q02_teams/build.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/q02_teams/build.py b/q02_teams/build.py index 3cf9d3cf..c62c3b9b 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,9 @@ def teams(data=data): # write your code here - #teams = - + teams = data['info']['teams'] + print(type(teams)) return teams +teams() + + From 65bcc5eed8bb3b24719b3e4c836205ee161f6e80 Mon Sep 17 00:00:00 2001 From: tracedence Date: Sat, 8 Sep 2018 09:34:52 +0000 Subject: [PATCH 3/7] Done --- q03_first_batsman/build.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/q03_first_batsman/build.py b/q03_first_batsman/build.py index 84984081..0ce755bc 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,13 @@ def first_batsman(data=data): # Write your code here + name = data['innings'][0]['1st innings']['deliveries'][0][0.1]['batsman'] + print(type(name)) + return name +name = first_batsman() +print(name) + - return name From 495712355bc8d6917775267c1c3ea4704a98cb80 Mon Sep 17 00:00:00 2001 From: tracedence Date: Sat, 8 Sep 2018 10:59:45 +0000 Subject: [PATCH 4/7] Done --- q04_count/build.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/q04_count/build.py b/q04_count/build.py index 6cf3dcbc..5a5a6bc1 100644 --- a/q04_count/build.py +++ b/q04_count/build.py @@ -1,11 +1,32 @@ +# %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 + number_of_bowl = len(data['innings'][0]['1st innings']['deliveries']) #no of ball in 1st innings + count = 0 #to count the number of ball RT pointing played + + for ball_no in range(number_of_bowl): #loop over each ball + #return dictionary of particular ball no + di = data['innings'][0]['1st innings']['deliveries'][ball_no] + + for ke in di.keys(): + if data['innings'][0]['1st innings']['deliveries'][ball_no][ke]['batsman'] == 'RT Ponting': + count = count + 1 + print(type(count)) return count + +deliveries_count() + + + + + + From d4dbb46870dcc191ddf8da305223bccda78d3bc8 Mon Sep 17 00:00:00 2001 From: tracedence Date: Sat, 8 Sep 2018 13:08:35 +0000 Subject: [PATCH 5/7] Done --- q05_runs/build.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/q05_runs/build.py b/q05_runs/build.py index a250631a..2ce99632 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,22 @@ def BC_runs(data): # Write your code here - + number_of_bowl = len(data['innings'][0]['1st innings']['deliveries']) #no of ball in 1st innings + runs = 0 #to count the number of runs scored by Brendon maCcullum + + for ball_no in range(number_of_bowl): #loop over each ball + + #return dictionary of particular ball no + di = data['innings'][0]['1st innings']['deliveries'][ball_no] + + for ke in di.keys(): + if data['innings'][0]['1st innings']['deliveries'][ball_no][ke]['batsman'] == 'BB McCullum': + + runs = runs + data['innings'][0]['1st innings']['deliveries'][ball_no][ke]['runs']['batsman'] + return(runs) + +BC_runs(data) + + From 6bd946a1d9530c3258edc0276cd5f8904e8cf9e9 Mon Sep 17 00:00:00 2001 From: tracedence Date: Sun, 9 Sep 2018 05:27:08 +0000 Subject: [PATCH 6/7] Done --- q06_bowled_players/build.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/q06_bowled_players/build.py b/q06_bowled_players/build.py index 914cb6d2..7a59f4c4 100644 --- a/q06_bowled_players/build.py +++ b/q06_bowled_players/build.py @@ -1,3 +1,4 @@ +# %load q06_bowled_players/build.py # Default Imports from greyatomlib.python_getting_started.q01_read_data.build import read_data data = read_data() @@ -6,6 +7,29 @@ def bowled_out(data=data): # Write your code here - + + bowled_players = [] #empty list for storing bowled players + + #total number of ball played in whole match + number_of_balls_played = len(data['innings'][1]['2nd innings']['deliveries']) + + for ball_number in range(number_of_balls_played): + + #dictionary of each ball + di = data['innings'][1]['2nd innings']['deliveries'][ball_number] + + for ke in di.keys(): # to get inside the ball details + + # check whether player out or not in particular ball + if ( 'wicket' in data['innings'][1]['2nd innings']['deliveries'][ball_number][ke].keys()): + + # check wicket get was bowled + if data['innings'][1]['2nd innings']['deliveries'][ball_number][ke]['wicket']['kind'] == 'bowled': + + bowled_players.append(data['innings'][1]['2nd innings']['deliveries'][ball_number][ke]['wicket']['player_out']) return bowled_players + +bowled_out(data) + + From 8c681bcd7f109b2d4c31a4d077d7a181b17a42dc Mon Sep 17 00:00:00 2001 From: tracedence Date: Sun, 9 Sep 2018 05:27:54 +0000 Subject: [PATCH 7/7] Done --- q07_extras/build.py | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/q07_extras/build.py b/q07_extras/build.py index cdeb803b..9d1d41d5 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,45 @@ def extras_runs(data=data): # Write your code here + #for Ist innings + + list_of_extra_runs_in_1st_innings = [] + number_of_balls_played = len(data['innings'][0]['1st innings']['deliveries']) + + + for ball_number in range(number_of_balls_played): + + di = data['innings'][0]['1st innings']['deliveries'][ball_number] + + for ke in di.keys(): + + if 'extras' in data['innings'][0]['1st innings']['deliveries'][ball_number][ke]: + list_of_extra_runs_in_1st_innings.append(data['innings'][0]['1st innings']['deliveries'][ball_number][ke]['extras']) + + + # for 2nd innings + + list_of_extra_runs_in_2nd_innings = [] + number_of_balls_played = len(data['innings'][1]['2nd innings']['deliveries']) + + + for ball_number in range(number_of_balls_played): + + di = data['innings'][1]['2nd innings']['deliveries'][ball_number] + + for ke in di.keys(): + + if 'extras' in data['innings'][1]['2nd innings']['deliveries'][ball_number][ke]: + list_of_extra_runs_in_2nd_innings.append(data['innings'][1]['2nd innings']['deliveries'][ball_number][ke]['extras']) + + + + + + difference = len(list_of_extra_runs_in_2nd_innings) - len (list_of_extra_runs_in_1st_innings) + return difference - difference = +extras_runs() - return difference