HW4Q6
user_7676782
python
3 years ago
1.5 kB
11
Indexable
# create number of title dictionary
def createWinNumDict(file):
winDict = {}
year=1954
line = file.readline()
while line != '':
# remove '\n'
tempLine = line.rstrip('\n')
# if we not already insert this club we will enter to this if statement
if tempLine not in winDict:
# avoid the war year
if year!=1956:
winDict[tempLine] = 1
# we will add +1 to the title count
elif tempLine in winDict:
winCount = winDict.get(tempLine)
winCount += 1
winDict[tempLine] = winCount
year+=1
line = file.readline()
# print(winDict)
return winDict
# create dictionary for years
def createYearWinDict(file):
year = 1954
yearDict = {}
line = file.readline()
while year <= 2021:
tempLine = line.rstrip('\n')
# avoid war year
if year == 1956:
year += 1
line = file.readline()
continue
else:
yearDict[year] = tempLine
year += 1
line = file.readline()
# print(yearDict)
return yearDict
def main():
fileContent1 = open('Alufa', 'r')
winNumDict = createWinNumDict(fileContent1)
fileContent1 = open('Alufa', 'r')
yearWinDict = createYearWinDict(fileContent1)
myYear = input("Enter a year:")
print(yearWinDict[int(myYear)])
print(winNumDict[yearWinDict[int(myYear)]])
main()
Editor is loading...