Click here to Skip to main content
15,907,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello dear experts


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"}, <br />
           "Joseph": {"name": "Joseph Boy", "address": "3 Tivoli Paris", "phone": "0800838383"}<br />
            "Bilbo": {"name": "Bilbo Baggin", "address": "4 White House Washington", "phone": "08055550838383"}<br />
         <br />
         }
         


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


my_dict["Don"]["name"]


or like so

my_dict["Bilbo"]["phone"]


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:
[python]
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

how would you extend the script!?

what do you say!?



love to hear from you

What I have tried:

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


my_dict["Don"]["name"]


or like so

my_dict["Bilbo"]["phone"]


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:
[python]
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 
Posted
Updated 5-May-19 3:27am
v2
Comments
[no name] 4-May-19 8:50am    
The fact is, people have "duplicate names". How many contacts do you have? You don't need "unique keys". You should be able to query: who called last; most often; talks the longest; you like "best"; has green hair; etc. .... to avoid having to worry about "duplicates".
Richard MacCutchan 4-May-19 9:57am    
A better idea would be to use a database* so you do not have to hardcode all the values in your program.

*Could be a simple CSV, XML or JSON file.

1 solution

Take a look at Serialization and Deserialization of Python Objects: https://code.tutsplus.com/tutorials/serialization-and-deserialization-of-python-objects-part-1--cms-26183[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900