Python Forum
Loop to find the best combination/score
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Loop to find the best combination/score
#13
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 :
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]
        break
You 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 ?
Reply


Messages In This Thread
RE: Loop to find the best combination/score - by KoinKoin - Dec-31-2022, 03:48 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to update score value? Mavoz 5 2,671 Nov-08-2022, 12:37 AM
Last Post: Mavoz
  Algorithm to generate a combination guvinicius2 5 2,680 Aug-15-2020, 10:42 PM
Last Post: deanhystad
  loops in combination with lists Juru 4 2,908 May-07-2020, 02:58 PM
Last Post: Marbelous
  Average score MartinEvtimov 5 7,008 Apr-02-2017, 07:35 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020