搜索获取键值的用户输入的最佳方法,下面的1从播放器列表创建字典并添加索引作为其值,但这不是我想要的,任何建议赞赏
import collections
Players = []
names = {}
#add player names
AddPlayers = int(input('How many players do you want to add: \n'))
for i in range(AddPlayers):
if i < AddPlayers:
item = input('Enter Player Name: ')
Players.append(item)
#create a dictionary from the player list
d = collections.OrderedDict()
for i,n in enumerate(Players):
if n not in d:
d[n] = [i+1]
print (d)
答案 0 :(得分:0)
您需要询问用户名和号码。您已经在使用for循环,而不是将名称添加到列表中,在循环中创建dic。
StackRouter