On Mar 11, 1:21 pm, noydb <jenn.du...@gmail.com> wrote: > Hello All, > > I am just looking to see if there is perhaps a more efficient way of > doing this below (works -- creates two random teams from a list of > players). Just want to see what the experts come up with for means of > learning how to do things better. > > Thanks for any responses! > > ### > import random > players = > teamA = random.sample(players, 4) > print teamA > teamB = [] > for p in players: > if p not in teamA: > teamB.append(p) > print teamB
How about: players = ["jake", "mike", "matt", "rich", "steve", "tom", "joe", "jay"] random.shuffle(players) teamA, TeamB = players[:4],players[4:] -- http://mail.python.org/mailman/listinfo/python-list