作者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