Dec-03-2019, 09:53 PM
(This post was last modified: Dec-03-2019, 09:53 PM by mrsenorchuck.)
Hello,
Hope you are well.
See below in bold, I want check if a key combination of club and year is present in a dictionary and then if it is append the value in [0] to a list but I am having trouble.
Any ideas?
Regards,
MRSENORCHUCK
# dictionary keys will be the (Club)
premier = {}
print()
# open the file
with open(r"C:\AOC_ASL_ASN\Project\League_Table2.csv") as data_file:
# read in the first line containing the headers
headers = data_file.readline()
# for each other line in the file
for line in data_file:
# split each line into components (remove white space from ends of line)
Team,Pos,Pld,HW,HD,HL,HG,HC,AW,AD,AL,AG,AC,W,D,L,G,C,Pts,Champ,Rel,Year = line.strip().split(",")
# insert the data into the dictionary
premier[str(Team),int(Year)] = ((int(Pos), int(Pld), int(HW), int(HD), int(HL), int(HG), int(HC), int(AW), int(AD), int(AL), int(AG), int(AC), int(W), int(D), int(L), int(G), int©,int(Pts),Champ,Rel))
# played list used in calc
Played = []
# go through each key in the dictionary
strTeam = input("Please pick a team: ")
for i in range(1993,2019):
if strTeam, i in premier.keys()
Played.append = premier[strTeam, i][0]
print(Played)
See sample data set
Team,Pos,Pld,HW,HD,HL,HG,HC,AW,AD,AL,AG,AC,W,D,L,G,C,Pts,Champ,Rel,Year
Manchester United,1,42,14,5,2,39,14,10,7,4,28,17,24,12,6,67,31,84,Yes,No,1993
Aston Villa,2,42,13,5,3,36,16,8,6,7,21,24,21,11,10,57,40,74,No,No,1993
Norwich City,3,42,13,6,2,31,19,8,3,10,30,46,21,9,12,61,65,72,No,No,1993
Blackburn Rovers,4,42,13,4,4,38,18,7,7,7,30,28,20,11,11,68,46,71,No,No,1993
Hope you are well.
See below in bold, I want check if a key combination of club and year is present in a dictionary and then if it is append the value in [0] to a list but I am having trouble.
Any ideas?
Regards,
MRSENORCHUCK
# dictionary keys will be the (Club)
premier = {}
print()
# open the file
with open(r"C:\AOC_ASL_ASN\Project\League_Table2.csv") as data_file:
# read in the first line containing the headers
headers = data_file.readline()
# for each other line in the file
for line in data_file:
# split each line into components (remove white space from ends of line)
Team,Pos,Pld,HW,HD,HL,HG,HC,AW,AD,AL,AG,AC,W,D,L,G,C,Pts,Champ,Rel,Year = line.strip().split(",")
# insert the data into the dictionary
premier[str(Team),int(Year)] = ((int(Pos), int(Pld), int(HW), int(HD), int(HL), int(HG), int(HC), int(AW), int(AD), int(AL), int(AG), int(AC), int(W), int(D), int(L), int(G), int©,int(Pts),Champ,Rel))
# played list used in calc
Played = []
# go through each key in the dictionary
strTeam = input("Please pick a team: ")
for i in range(1993,2019):
if strTeam, i in premier.keys()
Played.append = premier[strTeam, i][0]
print(Played)
See sample data set
Team,Pos,Pld,HW,HD,HL,HG,HC,AW,AD,AL,AG,AC,W,D,L,G,C,Pts,Champ,Rel,Year
Manchester United,1,42,14,5,2,39,14,10,7,4,28,17,24,12,6,67,31,84,Yes,No,1993
Aston Villa,2,42,13,5,3,36,16,8,6,7,21,24,21,11,10,57,40,74,No,No,1993
Norwich City,3,42,13,6,2,31,19,8,3,10,30,46,21,9,12,61,65,72,No,No,1993
Blackburn Rovers,4,42,13,4,4,38,18,7,7,7,30,28,20,11,11,68,46,71,No,No,1993