How to add a another value to a key in python

Posted by Nanowatt on Stack Overflow See other posts from Stack Overflow or by Nanowatt
Published on 2014-06-03T15:21:58Z Indexed on 2014/06/03 15:25 UTC
Read the original article Hit count: 357

Filed under:
|

First I'm sorry this might be a dumb question but I'm trying to self learn python and I can't find the answer to my question.

I want to make a phonebook and I need to add an email to an already existing name. That name has already a phone number attached. I have this first code:

phonebook = {}
phonebook ['ana'] = '12345'
phonebook ['maria']= '23456' , '[email protected]'

def add_contact():
       name = raw_input ("Please enter a name:")
       number = raw_input ("Please enter a number:")
       phonebook[name] = number

Then I wanted to add an email to the name "ana" for example: ana: 12345, [email protected]. I created this code but instead of addend a new value (the email), it just changes the old one, removing the number:

def add_email():
       name = raw_input("Please enter a name:")
       email = raw_input("Please enter an email:")
       phonebook[name] = email

I tried .append() too but it didn't work. Can you help me? And I'm sorry if the code is bad, I'm just trying to learn and I'm a bit noob yet :)

© Stack Overflow or respective owner

Related posts about python

Related posts about dictionary