pythonbook/Python 基础教程/集合 奥运会足球分组.py

23 lines
933 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# // map保存最终分组结果
# // key保存的是第几组value是该组对应的国家集合
import random
groupNum2Countrys = {}
strCountrys = "科特迪瓦,阿根廷,澳大利亚,塞尔维亚,荷兰,尼日利亚,日本,美国,中国,新西兰,巴西,比利时,韩国,喀麦隆,洪都拉斯,意大利";
countryList = strCountrys.split("")
for i in range(4):
lstGroup = []
# // 分第1组
# // 随机从集合中选出一个国家放到第1组里然后将这个选出的国家从原来集合中干掉删除
# // 重复以上步骤4次
for j in range(4):
selectIndex = random.randint(0,len(countryList)-1)
lstGroup.append(countryList[selectIndex])
countryList.remove(countryList[selectIndex])
groupNum2Countrys[i+1] = lstGroup
for key,value in groupNum2Countrys.items():
print('' + str(key) + '')
print(value)