嘗試這個(gè):from collections import defaultdictloaded_items = { 'Apple0': 2, 'Apple1': 3, 'Apple2': 8, 'Mango':10, 'Banana': 15, 'Grape0': 11, 'Grape1': 20, 'Potato': 5}items = defaultdict(dict)for k, v in loaded_items.items(): key_letter = ''.join(filter(str.isalpha, k)) items[key_letter][len(items[key_letter]) + 1] = vprint(items)
3 回答

當(dāng)年話下
TA貢獻(xiàn)1890條經(jīng)驗(yàn) 獲得超9個(gè)贊
由于它是 python 2.7,上面的 f-string 將不起作用。使用 '/home/{}/'.format(username) – Sergey Pugach
謝謝 Sergey Pugach,它完美地解決了我的問題。感謝大家在 2 小時(shí)內(nèi)解決了我的問題。祝你今天過得愉快!
添加回答
舉報(bào)
0/150
提交
取消