[問題] tuple 轉成 dictionary
想請問一下
如果我有像下列的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
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 3 篇):
Python 近期熱門文章
PTT數位生活區 即時熱門文章