Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
wafic fahme
3,309 PointsI am getting a list in list which is nonsense, how can I simply get rid of a list
import csv
import random
with open ("soccer_playerss.csv", newline='')as csvfile:
player_read = csv.DictReader(csvfile, delimiter =',')
player_list = list(player_read)
#print(player_list)
Dragons =[]
Sharks = []
Raptors = []
y_players = []
n_players = []
player = " "
def team_division(player):
for player in player_list:
if player['Soccer Experience'] == "YES":
y_players.append(player)
else:
n_players.append(player)
Dragons.append(y_players[0:len(y_players):3]+n_players[0:len(n_players):3])
Sharks.append(y_players[1:len(y_players):3]+ n_players[1:len(n_players):3])
Raptors.append(y_players[2:len(y_players):3] + n_players[2:len(n_players):3])
print ("DRAGONS: ",Dragons)
team_division(player)
3 Answers
Ken Alger
Treehouse TeacherWafic;
I think what you are asking is how to remove the list of experienced players and list of inexperienced players as separate lists for each team?
If that is indeed the case, during the team creation step in your code you will need to append each individual player to the team instead of the entire list of experienced/inexperienced players.
Is that what you are going after?
Ken
wafic fahme
3,309 PointsThank you, I figured our that they should go to a dictionary because putting teams in separate lists will make it difficult to send them letter. The problem that is confusing for me is just whether I shall divide them into 2 groups or use the original list of players?
wafic fahme
3,309 PointsI think I figured the above but what is still not figuring out is how to create a dictionary from 2 lists of different sizes. After numerous fails, I checked the internet but they always used Zip which I prefer not to use since we didn't cover it in the courses.