作者azulazure (獨在異鄉為異客)
看板Python
標題[問題] tuple 轉成 dictionary
時間Mon Mar 17 02:25:45 2008
想請問一下
如果我有像下列的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