Im writing an address book to use from terminal, how would I return the users contact info from the end-users input from the dictionary I created?

4 Years
Discussion Span
Last Post by clouds_n_things

I would need more information to answer that. What is the structure of the dictionary? Normally, I would key an address book on "name" so something like AddBook={"john doe":("8134789 Zubruzlechester", "Alpha Centauri", "999-555-1234")}. In that case I would get the telephone number, for instance, for John Doe, as: AddBook["john doe"][2]


Thanks for the reply rrashkin! My address book so far is formatted as such:

ab = {      'Kai'               : 'Phone Number: (555)-123-3120 or Email: something1@icloud.com', 
            'Anna'              : 'Phone Number: (555)-123-5385 or Email: something2@yahoo.com',
            'Donya'             : 'Phone Number: (555)-123-4161 or Email: something3@cs.com',
            'Elizabeth'         : 'Phone Number: (555)-123-8474 or Email: something4@yahoo.com', 
            'Derrick'           : 'Phone Number: (555)-123-3628 or Email: something5@instagram.com',
            'Ruth'              : 'Phone Number: (555)-123-8620 or Email: something6@instagram.com',
            'Nicole'            : 'Phone Number: (555) 123-3085 or Email: something7@gmail.com',


def in_addressbook(text):
    return key

key = input('Enter a contact information here: ')
if in_addressbook(key):
    print ('This contacts information is: {0}'.format(ab:0))

Edited by Nick Evan: Removed sensitive information. Fixed post formatting


The formatting for Derrick, Ruth, and Nicole are all temporary, but they should be formatted like the rest instead of their email taking on a new line. System kind of messed it up lol.


The "in" operater is used to look up a key in a dictionary --> dictionary tutorial http://www.greenteapress.com/thinkpython/html/thinkpython012.html Note rrashkin's advice above and store each item in a string or as an element of a sub-list so you can access them individually as (s)he has done. You should not post real phone numbers or e-mail addresses on a public forum.

key = input('Enter a contact information here: ')
if key in ab:
    print (ab[key])
    print("name not found")

Edited by woooee


Awesome, yeah I totally was not even paying attention when I posted my ab, (where the heck is my head at?), thanks for the advice everyone!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.