To make a world cup draw for 4 people, we can write a Python function that randomly assigns each person to a team. Here's one way to do it:
main.py270 chars12 linesIn this example, we define a function world_cup_draw that takes a list of player names as a parameter. The function creates a list of team names, shuffles it randomly, and then uses zip to combine the player names with the team names into a dictionary. The function returns this dictionary, which maps each player to a team.
To use this function, we simply call it with a list of player names, and it returns a dictionary that we can print out to see the results. In the example code above, we define a list of players ['Alice', 'Bob', 'Charlie', 'Dave'], and then call the world_cup_draw function with this list. The resulting dictionary is stored in the variable draw, and then printed out using print(draw).
gistlibby LogSnag