Creating a adressbook using a dictionary

hello dear experts

new to this site and fairly new to Python too. i am currently creating an ‘adress book’ python where i want to use dictionaries?

the plan:
I’m trying to create an little adress-book that has got an index
the index - think would be apropiate - could be the ‘nickname’ in the adress-book I want to give some options:

with the nickname the user can do some savings:

a. save a name of a person, the address of a person and subsequently the phone-number of that person. well - so far so good: - i want to use use a dictionaries, i want to have such a list. e.g

myList = [["Bill","Butcher", "4433345411"],["Billiboy","2 Rue Rivoli ", "0994399394800838383"]]

And then if I wanted to see a certain contact I would just use some more code to search for a pattern. And then i need to figure out how to do it with a dictionary?

well - i could do some starting points - with the usage of a dictionary:

i could probably start with this:

my_dict = {"Don": {"name": "Donald Jones", "address": "1 Rue Rivoli Paris ", "phone": "9444444411"}, 
           "Joseph": {"name": "Joseph Boy", "address": "3 Tivoli Paris", "phone": "0800838383"}            
            "Bilbo": {"name": "Bilbo Baggin", "address": "4 White House Washington", "phone": "08055550838383"}

But how to get access to the records that i have created: well i can access records using


or like so


by the way: Keys in a Python dictionary tend to be unique. Having a list of contacts in my adressbook the important thing is - there should be no name twice. That saind - we see that i can have the solution like this:

contacts = {}
contacts['Don'] = ["1 Rue Rivoli", 9444444411]
contacts['Joseph'] = ["3 Tivoli", 0800838383]

so adding data to a dictionary is based on the access operator .

the question is: how to extend the scipt a bit
should i make use of

  • raw input
  • arg.pop
    Some musings bout future enhancements:

Well i guess that - how to avoid issues when people have “duplicate names”. I guess that i need to have “unique keys”.

what would be fine is to be able to query: who called last; most often; talks the longest; you like “best”; has black hair; etc That said - it would be nice to have a database: With a database i would be very advanced - and besides that - i do not need to hardcode all the values in the program.

how would you extend the script!?

what do you say!?

love to hear from you

tend to

So what do you need to store in order to make these queries possible?

Yes, you’d have to hardcode them into the database, and then hardcode the database connection information in the program :wink: A database doesnt make your data storage work any less intensive. It can make certain types of querying easier though.

I know nothing about Python except that it exists and that it is similar to C++ but I have learned many languages in nearly half a century.

I suggest beginning by writing a program that can serialize in (read) the data and serialize out (write) the data.

Then write a simple program that allows you to show the data in a UI then add some editing capability such as add, modify and delete records.

Then learn how to do the same except using a database.

It will be good to learn how to do it more than one way.

Also think about the design of the data. Most people have more than one phone number; there are multiple ways to implement that. And most people have both a home address and a work address. And sometimes a phone number is used by multiple people. You can develop a more sophisticated design for your data but start simple with the intent to develop the design later.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.