看板 [ Python ]
討論串[問題] 找出dict中有相同value的key
共 3 篇文章
首頁
上一頁
1
下一頁
尾頁

推噓3(3推 0噓 1→)留言4則,0人參與, 4年前最新作者renshin (阿信)時間4年前 (2019/12/20 14:30), 編輯資訊
2
0
0
內容預覽:
請問要如何用dict中的value找key呢?. 例如有個dict. d = {'a':'100', 'b':'200', 'c':'200', 'd':'100', 'e':'150'}. 想把帶有相同value的key集合起來成各自一個list. 或者可能形成一個新的dict,如. Newd =
(還有34個字)

推噓4(4推 0噓 1→)留言5則,0人參與, 4年前最新作者Hsins (迅雷不及掩耳盜鈴)時間4年前 (2019/12/20 14:49), 4年前編輯資訊
0
0
2
內容預覽:
用 for 去遍歷 dict 中的 key 跟 value 就可以了. ```python. # declare the result dict to store reversed dict. result = {}. # traverse original dict. d = {'a': '100
(還有759個字)

推噓1(1推 0噓 0→)留言1則,0人參與, 4年前最新作者pingxx123 (皮)時間4年前 (2019/12/21 09:36), 編輯資訊
0
0
0
內容預覽:
使用defaultdict()加串列append(). from collections import defaultdict. d = {'a':'100', 'b':'200', 'c':'200', 'd':'100', 'e':'150'}. Newd = defaultdict(list)
(還有118個字)
首頁
上一頁
1
下一頁
尾頁