How can I print the possible combinations of a list in Python?

后端 未结 3 1186
温柔的废话
温柔的废话 2021-01-17 03:36

My list is:

groupA=[\'Russia\', \'Egypt\', \'Saudi Arabia\', \'Uruguay\']

So I want to print all the unique combinations of teams that will

3条回答
  •  南笙
    南笙 (楼主)
    2021-01-17 04:03

    This can do the trick:

    groupA = ['Russia', 'Egypt', 'Saudi Arabia', 'Uruguay']
    for index, country in enumerate(groupA):
        for rival in groupA[index+1:]:
            print('%s vs %s'%(country, rival) )
    

提交回复
热议问题