diff --git a/q01_read_data/build.py b/q01_read_data/build.py index e13d2f74..20a5b6e8 100644 --- a/q01_read_data/build.py +++ b/q01_read_data/build.py @@ -1,12 +1,15 @@ +# %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' - # Write your code here + with open('./data/ipl_match.yaml') as f: + data = yaml.load(f) + return data + +ocl=read_data() +type(ocl) + +print(ocl) - data = - # return data variable - return data diff --git a/q02_teams/build.py b/q02_teams/build.py index 3cf9d3cf..b26c21b3 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,37 @@ def teams(data=data): # write your code here - #teams = + teams = data['info']['teams'] + print(type(teams)) + return teams + +from greyatomlib.python_getting_started.q01_read_data.build import read_data +data = read_data() + +teams = data['info']['teams'] +type(teams) +type(data) +teams[1] +teams +for i in teams: + print(i) +len(teams) +teams.append('Crack Commandoes') +for k in teams: + print(k) +teams.insert(2,'Baja') +for j in teams: + print(j) +teams.pop() +teams +teams.reverse() +for i in teams: print(i) +del teams[0] +teams + +teams.reverse() +teams + + diff --git a/q03_first_batsman/build.py b/q03_first_batsman/build.py index 84984081..001af0dd 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,37 @@ def first_batsman(data=data): # Write your code here + name = data['innings'][0]['1st innings']['deliveries'][0][0.1]['batsman'] + return name +from greyatomlib.python_getting_started.q01_read_data.build import read_data +data = read_data() +piq = first_batsman() +type(piq) +type(data) +for i in data: print(i) +for i in data.values(): crass = i +type(data['innings'][0]) +data['innings'][0]['1st innings']['deliveries'][0][0.1]['batsman'] +data['innings'][0]['1st innings']['deliveries'][0][0.1] +type(crass[0]) +indict = crass[0] +for i in indict.values(): + print(i) +type(indict) +for x,y in indict.items(): + #print(type(x)) + #print(type(y)) + indict2=y + #print('the key is :'+x+' while the value is '+str(y)) +type(indict) +type(indict2) +for i in indict2.values(): inlist2 = i +type(inlist2) +for i,j in indict2.items(): print('the key is '+i+' while the value is '+str(j)) +type(inlist2[0]) +type(inlist2[0][0.1]) +inlist2[0][0.1]['batsman'] - return name diff --git a/q04_count/build.py b/q04_count/build.py index 6cf3dcbc..916b9a0a 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,24 @@ def deliveries_count(data=data): # Your code here + count=0 + x = data['innings'][0]['1st innings']['deliveries'] - + for i in x: + for k in i.values(): + print(k['batsman']) + if k['batsman'] == 'RT Ponting': + count = count + 1 + return count + +count=0 +x = data['innings'][0]['1st innings']['deliveries'] +for i in x: + for k in i.values(): + print(k['batsman']) + if k['batsman'] == 'RT Ponting': + count = count + 1 +print(count) + + diff --git a/q05_runs/build.py b/q05_runs/build.py index a250631a..9762b87b 100644 --- a/q05_runs/build.py +++ b/q05_runs/build.py @@ -1,12 +1,19 @@ +# %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 + runs = 0 + varfin=data['innings'][0]['1st innings']['deliveries'] + for y in varfin: + for v,w in y.items(): + if (w['batsman']) == 'BB McCullum': + runs=runs+(w['runs']['batsman']) + return(runs) + - return(runs) diff --git a/q06_bowled_players/build.py b/q06_bowled_players/build.py index 914cb6d2..584c860e 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() @@ -7,5 +8,16 @@ def bowled_out(data=data): # Write your code here + bowled_players = [] + varfin2=data['innings'][1]['2nd innings']['deliveries'] + for indict in varfin2: + for j,k in indict.items(): + for l,m in k.items(): + if ((l == 'wicket') and (m['kind'] == 'bowled')): + bowled_players.append(str(k['batsman'])) return bowled_players + +bowled_out(data) + + diff --git a/q07_extras/build.py b/q07_extras/build.py index cdeb803b..01281fd9 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() @@ -7,8 +8,33 @@ def extras_runs(data=data): # Write your code here + lst1=data['innings'][0]['1st innings']['deliveries'] + ext1 = [] + for inlst1 in lst1: + for x,y in inlst1.items(): + for m,n in y.items(): + if (m == 'runs'): + for r,s in n.items(): + if ((r == 'extras') and (s != 0)): + ext1.append(s) + break + + lst2=data['innings'][1]['2nd innings']['deliveries'] + ext2 = [] + for inlst2 in lst2: + for x,y in inlst2.items(): + for m,n in y.items(): + if (m == 'runs'): + for r,s in n.items(): + if ((r == 'extras') and (s != 0)): + ext2.append(s) + break + + difference = len(ext2)-len(ext1) - difference = + return difference + +extras_runs() +extras_runs() - return difference