So I have this list and a function that calculates the scores of my teams. i then put the team name and the score in a separate dictionary but the problem is that i have a few duplicate teams in this list. theres a second item which is whether or not the team response was valid if the result was this: team1 - score 100 - validresponse 0 i just want to get rid of the team even if its a duplicate, however of theres two duplicates of the SAME team and both their submissions were valid then i want to add their scores together and set it as one thing in the dictionary. the only problem is that when doing this, the dictionary automatically disregards the other duplicates.
Here's my code:
import numpy as np
import pandas as pd
mylist = []
with open("input1.txt", "r") as input:
for line in input:
items = line.split()
mylist.append([int(item) for item in items[0:]])
amountOfTestCases = mylist[0][0]
amountOfTeams = mylist[1][0]
amountOfLogs = mylist[1][1]
count = 1
count2 = 1
mydict = {}
teamlist = []
for i in mylist[2:]:
count2 += 1
teamlist.append(mylist[count2][1])
def find_repeating(lst, count=2):
ret = []
counts = [None] * len(lst)
for i in lst:
if counts[i] is None:
counts[i] = i
elif i == counts[i]:
ret += [i]
if len(ret) == count:
return ret
rep_indexes = np.where(pd.DataFrame(teamlist).duplicated(keep=False))
print(teamlist)
print(rep_indexes)
duplicate = find_repeating(teamlist)
def calculate_points(row):
points = mylist[row][3] * 100
points -= mylist[row][0]
return points
for i in teamlist:
count += 1
mydict['team%s' % mylist[count][1]] = calculate_points(count)
print(mydict)
the teamlist = [5, 4, 1, 2, 5, 4]