题解 | #字典新增#
字典新增
https://www.nowcoder.com/practice/a69d651105ee4cfd86c56418f0aa9de3
import sys dictionary = {'a': ['apple', 'abandon', 'ant'], 'b': ['banana', 'bee', 'become'], 'c': ['cat', 'come'], 'd': 'down'} letter = input() word = input() if letter in dictionary: value = dictionary[letter] if type(value) == list: words = list(value) else: words = list((value,)) words.append(word) dictionary.update({letter:words}) else: dictionary.update({letter:word}) print(dictionary)