Python 在字典中将str对象转换为int

Python 在字典中将str对象转换为int,python,dictionary,Python,Dictionary,我目前正在用python为一个yatzhee游戏制作记分板,我使用字典关联玩家的分数将插入到表中的位置。 字典从一开始就是这样的: self.lista={"aces":'',"twos":'',"threes":'',"fours":''} 例如,当我将数字25与“aces”关联时,我希望它被解释为一个整数,因此下次我将点添加到“aces”时,它将它们与25相加。有办法吗 self.lista = {"aces":'',"twos":'',"threes":'',"fours":''} s

我目前正在用python为一个yatzhee游戏制作记分板,我使用字典关联玩家的分数将插入到表中的位置。 字典从一开始就是这样的:

 self.lista={"aces":'',"twos":'',"threes":'',"fours":''}
例如,当我将数字25与“aces”关联时,我希望它被解释为一个整数,因此下次我将点添加到“aces”时,它将它们与25相加。有办法吗

self.lista = {"aces":'',"twos":'',"threes":'',"fours":''}
self.lista['aces'] = 25 --> # 25
self.lista['aces'] += 25 --> # 50
OT(供将来参考): 您可以通过以下方式使用键初始化dict:

keys = ['aces', 'twos', 'threes', 'fours']
self.lista = dict.fromkeys(keys)
print self.lista --> # {'aces': None, 'fours': None, 'twos': None, 'threes': None}

对dict不关心插入什么类型的值,你可以输入一个int。我看不到任何连接。这意味着你不必创建一个新的dict来调用fromkeys-
dict.fromkeys
{}好。fromkeys
让它成为伙计,现在它更快:)