[問題] tuple 轉成 dictionary

看板Python作者 (獨在異鄉為異客)時間17年前 (2008/03/17 02:25), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/3 (看更多)
想請問一下 如果我有像下列的tuple (to, you), (to, me), (to, him), (to, us) 等等 要怎麼樣把這些tuple轉成像下面的dictionary {to: ['you', 'me', 'him', 'us']} 我試過用 d = {} for item in tuple: if item[0] in d: d[item[0]] += item[1] 但是行不通 先謝過大家了 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 69.143.181.102
文章代碼(AID): #17tMOgdx (Python)
文章代碼(AID): #17tMOgdx (Python)