possible pairings in a set

Ross ross.jett at gmail.com
Sun Apr 5 02:42:58 CEST 2009

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):
	return cleanlist
	start = 0
	follow = start +1
	finallist = []
	while follow <= len(cleanlist)-1:
		for player in cleanlist:
			mini = cleanlist[start],cleanlist[follow]
			follow +=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?

More information about the Python-list mailing list