Writing a simple address book in python

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dipak Singh
    New Member
    • Feb 2011
    • 8

    Writing a simple address book in python

    Hi All,
    I am learning python by myself. I have some knowledge about C. But What I need to give output for an addressbook using python is(By taking user input) :

    Name Mobile Address
    abc 123 xyz

    Further if I append some entries in the book like
    mno 456 stu

    I need the address book to get updated and displayed as:

    Name Mobile Address
    abc 123 xyz
    mno 456 stu


    But as I am new to python, I am not able to properly align the entries. Kindly help. The code written by me is attached. Thanks in advance for any help.

    Please note: this is not a school homework!!!
    Regards,
    Dipak Kr. Singh
    Attached Files
    Last edited by bvdet; May 17 '11, 06:15 PM. Reason: Corrected title
  • dwblas
    Recognized Expert Contributor
    • May 2008
    • 626

    #2
    There is more than one way to format in Python. See 5.6.2 here for specific info.
    Code:
    test_list = [['abc', '123 xyz'], ['mno', '456 stu']]
    for person in test_list:
        print "%-5s  %-10s" % (person[0], person[1])

    Comment

    • Ephexeve
      New Member
      • May 2011
      • 20

      #3
      You can make a dictionary, the key will be the name and the value the address withing a list.

      Comment

      Working...