Skip to content

Commit Live PR #277

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions q01_read_data/build.py
Original file line number Diff line number Diff line change
@@ -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()


14 changes: 12 additions & 2 deletions q02_teams/build.py
Original file line number Diff line number Diff line change
@@ -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





7 changes: 5 additions & 2 deletions q03_first_batsman/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
32 changes: 31 additions & 1 deletion q04_count/build.py
Original file line number Diff line number Diff line change
@@ -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)












33 changes: 31 additions & 2 deletions q05_runs/build.py
Original file line number Diff line number Diff line change
@@ -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)
23 changes: 20 additions & 3 deletions q06_bowled_players/build.py
Original file line number Diff line number Diff line change
@@ -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
28 changes: 26 additions & 2 deletions q07_extras/build.py
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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