games = {"1":"GTA V,FarCry 5","2":"Watchdogs II,South Park: The Stick of Truth","3":"For Honor,The Forest,South Park: The Fractured but whole"}for games_value in games.values(): games_value.split(",")但这没有任何作用...我想要的是:games = {"1":"GTA V","FarCry 5""2":"Watchdogs II","South Park: The Stick of Truth""3":"For Honor","The Forest","South Park: The Fractured but whole"}
1 回答
慕无忌1623718
TA贡献1744条经验 获得超4个赞
您已经接近解决方案了,请查看此代码。
games = {
"1":"GTA V,FarCry 5",
"2":"Watchdogs II,South Park: The Stick of Truth",
"3":"For Honor,The Forest,South Park: The Fractured but whole"
}
for games_key in games:
games[games_key] = games[games_key].split(",")
print(games)
#OUTPUT: {'1': ['GTA V', 'FarCry 5'], '2': ['Watchdogs II', 'South Park: The Stick of Truth'], '3': ['For Honor', 'The Forest', 'South Park: The Fractured but whole']}
逻辑:
迭代字典键
在字典键处写入分割后的值
添加回答
举报
0/150
提交
取消