The goal of this code is to split a CSV file of soccer players into 3 teams. In the file each player had an experience level, either played before or not. The teams should all have the same amount of experienced and non experienced players.
When I run this nothing happens.
import csv
def add_exp_players(players):
copy = players
counter = 0
while counter <= len(players):
for player in players:
if player["Soccer Experience"] == "YES":
dragons.append(copy.pop(0))
sharks.append(copy.pop(0))
raptors.append(copy.pop(0))
counter += 3
def add_non_exp_players(players):
copy = players
counter = 0
while counter <= len(players):
for player in players:
if player["Soccer Experience"] == "YES":
dragons.append(copy.pop(0))
sharks.append(copy.pop(0))
raptors.append(copy.pop(0))
counter += 3
def create_exp_lists(players):
for player in players:
if player["Soccer Experience"] == "YES":
exp_players.append(player)
else:
non_exp_players.append(player)
with open('soccer_players.csv') as file:
all_players = [{key: value for key, value in row.items()} for row in csv.DictReader(file)]
dragons = []
sharks = []
raptors = []
exp_players = []
non_exp_players = []
create_exp_lists(all_players)
add_exp_players(exp_players)
add_non_exp_players(non_exp_players)
print(exp_players)
print(non_exp_players)
print(dragons)
print(sharks)
print(raptors)
Comments
Post a Comment