我試圖刪除下面列表中每個項目的最後2位數字。如何刪除列表中元素的最後2個字符?
keys = ['2013', '1101', '1201', '1301', '1401', '1402', '1403', '2100', '2150', '3201', '5201', '5301', '9810', '9820', '9830', '2013', '1101', '1201', '1202', '1301', '1304', '1401', '1402', '1403', '2100', '2150', '3401', '5201', '5301', '9810', '9820', '9830', '2013', '1101', '5201', '2013', '1101', '1201', '1401', '1402', '1403', '2100', '5201', '5301', '5402', '9810', '9820', '9830', '2013']
for n,k in keys:
keys[n] = keys[n][0]+keys[n][1]
我不斷收到ValueError異常:值過多解壓
作爲一個側面說明,你的代碼也將工作,如果你沒有'n個,在歷數(鍵)K:' – mgilson 2013-02-28 21:28:29