This is the second time I’ve implemented something like this and I suspect there has to be a better (read: more pythonic) way to do this:
phone_book = {}
def add_number(name,number):
if name in phone_book:
phone_book['name'].append(number)
else:
phone_book['name'] = [number]
I realize the code can likely be made more concise with conditional assignments, but I suspect there’s likely a better way to go about this. I’m not interested in only making the code shorter.
Use
dict‘ssetdefaultlike this: