import itertools def number_of_pool(players): # This function calculate the number of pools given a number of players (now it favor 3 players pools) i = players // 3 return i all_the_pools = {} def make_pools_dict(categorie,number_of_players): # this function add the pool_dict to all_the_pools and make a place for each players all_the_pools[categorie] = {} #add categorie as a dict entry in all_the_pools letters = 'abcdefghijklmnopqrstuvwxyz' pools = [] for x in range(0,number_of_pool(number_of_players)): #create each pool of the categore as a list all_the_pools[categorie][categorie + "_" +letters[x].upper()] = [] x = 0 for i in range(1,number_of_players + 1): all_the_pools[categorie][categorie + "_" +letters[x].upper()].append("player"+str(i)) x +=1 if x == number_of_pool(number_of_players): x = 0 make_pools_dict("SMA",18) make_pools_dict("DXA", 13) def versus(all_the_pools): # This function take each pool individually and create an array with each match to be played for i in all_the_pools: for j in all_the_pools[i]: out_list = [] for k in range(len(all_the_pools[i][j])): out_list.extend(itertools.combinations(all_the_pools[i][j], 2)) print out_list for k in all_the_pools[i][j]: index_list.append(k) match_list = itertools.combinations(index_list, 2) print match_list versus(all_the_pools)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question