看板
[ Python ]
討論串[問題] 找出dict中有相同value的key
共 3 篇文章
首頁
上一頁
1
下一頁
尾頁
內容預覽:
請問要如何用dict中的value找key呢?. 例如有個dict. d = {'a':'100', 'b':'200', 'c':'200', 'd':'100', 'e':'150'}. 想把帶有相同value的key集合起來成各自一個list. 或者可能形成一個新的dict,如. Newd =
(還有34個字)
內容預覽:
用 for 去遍歷 dict 中的 key 跟 value 就可以了. ```python. # declare the result dict to store reversed dict. result = {}. # traverse original dict. d = {'a': '100
(還有759個字)
內容預覽:
使用defaultdict()加串列append(). from collections import defaultdict. d = {'a':'100', 'b':'200', 'c':'200', 'd':'100', 'e':'150'}. Newd = defaultdict(list)
(還有118個字)
首頁
上一頁
1
下一頁
尾頁