Wow thank you very much @deanhystad !
I adapted it to my script and work great!
May I ask the difference between my code and yours ?
I feel like the step was the same, only the method was different.
I was using a df for my players list :
I adapted it to my script and work great!
May I ask the difference between my code and yours ?
I feel like the step was the same, only the method was different.
I was using a df for my players list :
df1 = pd.DataFrame.from_dict(data)You used a class :
players = [Player(i) for i in range(1, 61)]Then, combinations of teams + score :
for index in list(combinations(df1.index,5)): dictIndexScore[index] = df1.loc[index,:]["Score1"].sum(axis=0)Again you used class to do the same :
teams = [Team(pics) for pics in combinations(players, 5)]Finally to get the best team, i was sorting my dict and test the avg value:
for i in sorted(dictIndexScore.items(), key=lambda x:x[1], reverse=True): if df1.loc[i[0],:]["10Aver1"].sum(axis=0) - df1.loc[i[0],:]["10Aver1"].max(axis=0) < 121: bestIndex = i[0] bestSum = i[1] breakYou looked for the max when avg is under 121:
teams = [team for team in teams if team.cap <= 120] best_team = max(teams, key=lambda p: p.score)Using class instead of df is the reason why it's faster ?