Input below:
list_1 = [TeamA,TeamB,TeamC,TeamD]
Output should be like below
TeamA TeamB
TeamA TeamC
TeamA TeamD
TeamB TeamC
TeamB TeamD
TeamC TeamD
CodePudding user response:
list_1 = ['TeamA', 'TeamB', 'TeamC', 'TeamD']
print("\n".join([f"{a} {b}" for a in list_1 for b in list_1[list_1.index(a) 1:]]))
Output:
TeamA TeamB
TeamA TeamC
TeamA TeamD
TeamB TeamC
TeamB TeamD
TeamC TeamD
CodePudding user response:
list_1 = ["TeamA","TeamB","TeamC","TeamD"]
fixtures = [[a, b] for i, a in enumerate(list_1) for b in list_1[i 1:]]
print(fixtures)
Output
[['TeamA', 'TeamB'], ['TeamA', 'TeamC'], ['TeamA', 'TeamD'], ['TeamB', 'TeamC'], ['TeamB', 'TeamD'], ['TeamC', 'TeamD']]
CodePudding user response:
The combinations
function of itertools module can do exactly what you want : (https://docs.python.org/3/library/itertools.html#itertools.combinations)
from itertools import combinations
list(itertools.combinations(list_1, r = 2))