题解 | #字典新增#
字典新增
https://www.nowcoder.com/practice/a69d651105ee4cfd86c56418f0aa9de3
from collections import defaultdict c = input() word = input() dd = defaultdict(list) dict1 = { "a": ["apple", "abandon", "ant"], "b": ["banana", "bee", "become"], "c": ["cat", "come"], "d": "down", } dd.update(dict1) if isinstance(dd[c], str): tmp = dd[c] dd[c] = [dd[c], word] if dd[c] == []: dd[c] = word print(dict(dd))