rdata3 = [["ATL",0,0,0], ["CHC",0,0,0], ["CLE",0,0,0]]
wins = {
"ATL" : 0,
"CHC" : 0,
"CLE" : 0
}
losses = {
"ATL" : 0,
"CHC" : 0,
"CLE" : 0
}
ties = {
"ATL" : 0,
"CHC" : 0,
"CLE" : 0
}
rdata1 = {
"ATL" : [0,0,0],
"CHC" : [0,0,0],
"CLE" : [0,0,0]
}
rdata2 = {
"ATL" : {"wins":0, "losses":0, "ties":0},
"CHC" : {"wins":0, "losses":0, "ties":0},
"CLE" : {"wins":0, "losses":0, "ties":0}
}
teams = ["ATL","CHC","CLE"]
rdata2 = {}
for team in teams:
rdata2[team] = {"wins":0, "losses":0, "ties":0}
print(rdata2)
{'ATL': {'wins': 0, 'losses': 0, 'ties': 0}, 'CHC': {'wins': 0, 'losses': 0, 'ties': 0}, 'CLE': {'wins': 0, 'losses': 0, 'ties': 0}}
# How to update rdata2?
# 12/22/2020:CHC:ATL:10:5
d = rdata2["CHC"] # read value from rdata2 of key "CHC" into d
d["wins"] = d["wins"] + 1 # update d
rdata2["CHC"] = d # write value back to rdata2 for key "CHC" - SEEMS to be UNNECESSARY UNEXPECTEDLY
d = rdata2["ATL"] # read value from rdata2 of key "CHC" into d
d["losses"] = d["losses"] + 1 # update d
rdata2["ATL"] = d # write value back to rdata2 for key "CHC" - SEEMS to be UNNECESSARY UNEXPECTEDLY
print(rdata2)
{'ATL': {'wins': 0, 'losses': 0, 'ties': 0}, 'CHC': {'wins': 1, 'losses': 0, 'ties': 0}, 'CLE': {'wins': 0, 'losses': 0, 'ties': 0}}
rdata2["CHC"]["wins"]
1
rdata2 = {
"ATL" : {"wins":2, "losses":5, "ties":0},
"CHC" : {"wins":4, "losses":3, "ties":1},
"CLE" : {"wins":2, "losses":5, "ties":0}
}
print(rdata2)
{'ATL': {'wins': 2, 'losses': 5, 'ties': 0}, 'CHC': {'wins': 4, 'losses': 3, 'ties': 1}, 'CLE': {'wins': 2, 'losses': 5, 'ties': 0}}
# we want to construct the list percent = [("ATL",0.714),("CHC",0.563),()] from rdata2
result = []
for team in rdata2:
percent = (rdata2[team]["wins"] + 0.5 * rdata2[team]["ties"]) / \
(rdata2[team]["wins"] + rdata2[team]["losses"] + rdata2[team]["ties"])
result.append((team,round(percent,3)))
print(result)
[('ATL', 0.286), ('CHC', 0.562), ('CLE', 0.286)]
sorted_result = sorted(result, key=lambda x:x[1], reverse=True)
print(sorted_result)
[('CHC', 0.562), ('ATL', 0.286), ('CLE', 0.286)]
x = [1,2,3]
x.reverse()
print(x)
[3, 2, 1]
def reverse(xs):
result = []
for x in xs:
result.insert(0,x)
return result
xs = [1,2,3]
ys = reverse(xs)
print(xs)
print(ys)
[1, 2, 3] [3, 2, 1]
def main():
pass
def read_data_teams(dname):
pass # should return a list of tuples containing team information
def read_data_games(dname):
pass # should return a list of tuples containing game information
def standings(teams,games):
pass # no return value; only prints
def results(teams,games):
pass # no return value; only prints