# Online Python compiler (interpreter) to run Python online. # Write Python 3 code in this online editor and run it. import random def split_chunks2(player_dict, chunk_count=4): result = [[] for i in range(chunk_count)] team_weights = [0]*chunk_count i = 0 for player, weight in player_dict: result[i].append(player) team_weights[i] += weight i = team_weights.index(min(team_weights)) return result, team_weights # To change player weight, change second fields for each paranthesis player_list = [("Mert", 10), ("Muzeyya", 9), ("Davulcu", 9), ("QC", 8), ("wiki", 8), ("Nobi", 8), ("Mertbey", 8), ("ode", 7), ("soba", 7), ("erlinda", 7), ("custme", 6), ("njos", 6), ("elfin", 5), ("uyku", 5), ("bdl", 3), ("nina", 3) ] num_team = 4 def main(): print("--------- General info --------------") print("Participants\n" + "\n".join([f"{player}: {weight}" for player, weight in player_list])) sum_weight = sum([player[1] for player in player_list]) weight_per_team = sum_weight / num_team print(f"\nTotal player weight: {sum_weight}, Number of team: {num_team}, per team weight: {weight_per_team}") random.shuffle(player_list) player_list.sort(key=lambda tup: tup[1], reverse=True) team_list, team_weights = split_chunks2(player_list, num_team) print("\n--------- Team formations -----------") for index, (team, weight) in enumerate(zip(team_list, team_weights), start=1): print(f"Team {index}: {' '.join(team)} | Team weight: {weight}") print("\n-------- Team matches ---------------") team_numbers = list(range(1, num_team+1)) random.shuffle(team_numbers) print(" <---> ".join([f"Team {team_index}" for team_index in team_numbers[:2]])) print(" <---> ".join([f"Team {team_index}" for team_index in team_numbers[2:]])) if __name__ == "__main__": main()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question