This is the second time I implemented something like this, and I suspect there should 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 understand that the code may be shorter with conditional assignments, but I suspect that probably the best way to do this. I'm not interested in making the code shorter.
source share