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貢獻(xiàn)1744條經(jīng)驗(yàn) 獲得超4個(gè)贊
您已經(jīng)接近解決方案了,請(qǐng)查看此代碼。
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']}
邏輯:
迭代字典鍵
在字典鍵處寫入分割后的值
添加回答
舉報(bào)
0/150
提交
取消