diff --git a/q01_read_data/build.py b/q01_read_data/build.py index e13d2f74..70a58658 100644 --- a/q01_read_data/build.py +++ b/q01_read_data/build.py @@ -1,12 +1,7 @@ import yaml def read_data(): + with open('./data/ipl_match.yaml') as f: + data = yaml.load(f) + return 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 = - - # return data variable - return data diff --git a/q02_teams/build.py b/q02_teams/build.py index 3cf9d3cf..d5cfc73b 100644 --- a/q02_teams/build.py +++ b/q02_teams/build.py @@ -4,8 +4,8 @@ # solution def teams(data=data): - - # write your code here - #teams = - + teams = data['info']['teams'] return teams + + + diff --git a/q03_first_batsman/build.py b/q03_first_batsman/build.py index 84984081..3050a3bb 100644 --- a/q03_first_batsman/build.py +++ b/q03_first_batsman/build.py @@ -1,13 +1,15 @@ -# Default Imports +# default imports +from unittest import TestCase from greyatomlib.python_getting_started.q01_read_data.build import read_data + data = read_data() -# Your Solution def first_batsman(data=data): + + batsman_name = data['innings'][0]['1st innings']['deliveries'][0][0.1]['batsman'] + return batsman_name - # Write your code here - +first_batsman() - return name diff --git a/q04_count/build.py b/q04_count/build.py index 6cf3dcbc..c67f1388 100644 --- a/q04_count/build.py +++ b/q04_count/build.py @@ -1,11 +1,23 @@ +# %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 + deliveries_faced = data['innings'][0]['1st innings']['deliveries'] + for ele in deliveries_faced: + for key, value in ele.items(): + batsman_name = value['batsman'] + print (batsman_name) + if (batsman_name == 'RT Ponting'): + count = count+1 return count + +deliveries_count(data) + + + + + diff --git a/q05_runs/build.py b/q05_runs/build.py index a250631a..5d22cfa1 100644 --- a/q05_runs/build.py +++ b/q05_runs/build.py @@ -1,12 +1,25 @@ + # Default Imports from greyatomlib.python_getting_started.q01_read_data.build import read_data data = read_data() +# Your Solution Here +def BC_runs (data=data): + # Initialize the variable + runs = 0 + runs_scored = 0 + # Read list value for deliveries + deliveries_info = data['innings'][0]['1st innings']['deliveries'] + for ele in deliveries_info: + # Read jey value pair + for key, value in ele.items(): + batsman_name = value['batsman'] + runs_scored = value['runs']['batsman'] + #Check specific batsman + if (batsman_name == 'BB McCullum'): + runs += runs_scored + return runs +data = read_data() +print (data['innings'][0]['1st innings']['deliveries'][0][0.1]) +BC_runs(data) -# Your Solution -def BC_runs(data): - - # Write your code here - - - return(runs) diff --git a/q06_bowled_players/build.py b/q06_bowled_players/build.py index 914cb6d2..76a0f51c 100644 --- a/q06_bowled_players/build.py +++ b/q06_bowled_players/build.py @@ -1,11 +1,30 @@ + # Default Imports from greyatomlib.python_getting_started.q01_read_data.build import read_data data = read_data() +# Your Solution Here +def bowled_out (data=data): + # Initialize the variable + bowled_players =[] + runs = 0 + runs_scored = 0 + # Read list value for deliveries + deliveries_info = data['innings'][1]['2nd innings']['deliveries'] + for i in range (len(deliveries_info)): + for key, value in (data['innings'][1]['2nd innings']['deliveries'][i]).items(): + batsman_name = value['batsman'] + if ('wicket' in data['innings'][1]['2nd innings']['deliveries'][i][key].keys()): + wicket_kind = value ['wicket'] + for key, value in wicket_kind.items(): + if (value == 'bowled'): + bowled_players.append(batsman_name) + return bowled_players + + + + + -# Your Solution -def bowled_out(data=data): - # Write your code here - return bowled_players diff --git a/q07_extras/build.py b/q07_extras/build.py index cdeb803b..3e38bf0d 100644 --- a/q07_extras/build.py +++ b/q07_extras/build.py @@ -1,14 +1,54 @@ -# 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 +#Default Imports +from greyatomlib.python_getting_started.q01_read_data.build import read_data +data = read_data() +# Your Solution Here +def extras_runs (data=data): + # Initialize the variable + extras1 = 0 + extras2 = 0 + difference = 0 + # Read list value for deliveries + for num in range (2): + wides =0 + legbyes =0 + others = 0 + if (num ==0): + inning_sequence = '1st innings' + + else: + inning_sequence = '2nd innings' + + deliveries_info = data['innings'][num][inning_sequence]['deliveries'] + + #iterate through deliveries + for i in range (len(deliveries_info)): + for key, value in (data['innings'][num][inning_sequence]['deliveries'][i]).items(): + if ('extras' in data['innings'][num][inning_sequence]['deliveries'][i][key].keys()): + extra_key_value = value['extras'] + for key, value in extra_key_value.items(): + + if (key == 'wides'): + wides += value + else: + if (key == 'legbyes'): + legbyes += value + else: + others +=others + if (num ==0): + extras1 = wides + legbyes + others + else: + extras2 = wides + legbyes + others + + if (extras1>extras2): + difference = extras1 - extras2 + else: + difference = extras2 - extras1 + return difference + +extras_runs(data) - difference = - return difference