使用字典创建地址簿 [英] Creating an adress-book using dictionary

查看:84
本文介绍了使用字典创建地址簿的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的专家们,你好吗?




i我目前正在创建一个'地址簿'python,我想用词典吗?



计划:

我正在尝试创建一个有索引的小地址簿 

指数 - 认为是合适的 - 可能是地址簿中的'昵称'我想给出一些选择:



用户的昵称可以节省一些:



a。保存一个人的姓名,一个人的地址以及随后的那个人的电话号码。

好​​ - 到目前为止很好: - 我想使用词典, 我想要这样的清单。例如



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

然后,如果我想看到某个联系人,我会使用更多代码来搜索模式。 

然后我需要弄清楚如何用字典做什么?





好​​ - 我可以做一些起点  - 使用字典: 



i可能从这开始:



 my_dict = {Don :{name:Donald Jones,address:1 Rue Rivoli Paris,phone:9444444411},< br /> 
  &NBSP; &NBSP; &NBSP; &NBSP;  Joseph:{name:Joseph Boy,address:3 Tivoli Paris,phone:0800838383}< br />
  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; Bilbo:{name:Bilbo Baggin,地址:4 White House Washington,phone:08055550838383}< br />
  &NBSP; &NBSP; &NBSP;  < br />
  &NBSP; &NBSP; &NBSP; &NBSP;}

&NBSP; &NBSP; &NBSP; &NBSP;  





但是如何访问我创建的记录:我可以使用
$访问记录b $ b



my_dict [Don] [name]





或类似如此



my_dict [Bilbo] [电话]





顺便说一句:Python字典中的键往往是唯一的。在我的地址簿中有一个联系人列表,重要的是 - 应该没有两次名称。 那是圣徒 - 我们看到了这样的解决方案:

[python]

contacts = {}

contacts [' Don'] = [1 Rue Rivoli,9444444411]

联系人['Joseph'] = [3 Tivoli,0800838383]





所以将数据添加到词典是基于访问运算符[]。 



问题是:如何扩展scipt有点

我应该使用



- 原始输入

- arg.pop



你会如何扩展剧本!?



你怎么说!?







很高兴收到你的来信



我尝试过:



但是如何访问我创建的记录:我可以使用


my_dict [Don] [name]


或类似因此

my_dict [Bilbo ] [电话]


顺便说一下:Python词典中的键t结束是独一无二的。在我的地址簿中有一个联系人列表,重要的是 - 应该没有两次名称。 那是圣徒 - 我们看到我可以得到这样的解决方案:
[python]
contacts = {}
contacts ['Don'] = [1 Rue Rivoli,9444444411 ]
联系人['Joseph'] = [3 Tivoli,0800838383]


所以将数据添加到字典是基于访问运算符[]。 

问题是:如何使用

- 原始输入
- arg.pop p $ p>

解决方案

看看序列化和Python对象的反序列化:https://code.tutsplus.com/tutorials/serialization-and-deserialization-of-python- objects-part-1 - cms-26183 [ ^ ]


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 

解决方案

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[^]


这篇关于使用字典创建地址簿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆