I'm new to python and I'm trying to come up with a function that takes a given number of players in a game and returns all possible unique pairings. Here's the code I've come up with so far, but I'm not getting the output I'd like to:
def all_pairings(players): cleanlist = [] for i in range(players): cleanlist.append(i) return cleanlist start = 0 follow = start +1 finallist = [] while follow <= len(cleanlist)-1: for player in cleanlist: mini = cleanlist[start],cleanlist[follow] finallist.append(mini) follow +=1 start+=1 return finallist If I were to execute the function with all_pairings(4), I want to get the output [[0,1],[0,2],[0,3],[1,2],[1,3],[2,3]. Instead, I get [0,1,2,3] with the code I currently have. Can you guys help me out? Also, if my code is considered ugly or redundant by this community, can you make suggestions to clean it up? -- http://mail.python.org/mailman/listinfo/python-list