0. When you hear the little friends talking about "maps", "hash", "hash" or when the "associative arrays", in fact, that is what they discuss it?
me: Dictionary
1. Try to data ( 'F': 70, 'C': 67, 'h': 104, 'i': 105, 's': 115) to create and access a dictionary corresponding to the key value of 'C' ?
me:
dict1={'F': 70, 'C': 67, 'h': 104, 'i': 105, 's': 115} print(dict1["C"])
2. Use square brackets ( "[]") enclosed data we call lists, use curly braces ( "{}") We called dictionary data enclosed, right?
me: No, just a list of expressions is [] enclosed data, expressed in the form dictionary is the use of the data enclosed {}, {} enclosed but using data dictionary is not expressed
Answer:
3. How do you understand the dictionary can do some things, but the "universal" list but difficult to achieve (Chenqie do T_T)?
me:
Answer:
4. the following code, they are performing the same operation it? You could tell the difference right?
a = dict(one=1, two=2, three=3) b = {'one': 1, 'two': 2, 'three': 3} c = dict(zip(['one', 'two', 'three'], [1, 2, 3])) d = dict([('two', 2), ('one', 1), ('three', 3)]) e = dict({'three': 3, 'one': 1, 'two': 2})
me:
Answer:
5. As shown, you can infer played codes mosaic part of it?
me:
= DATE " 100, small turtles, M " MyDict = {} (MyDict["id"],MyDict["name"],MyDict["sex"])=date.split(",",3) print("ID: " + MyDict["id"]) print("name: " + MyDict["name"]) print("sex: " +MyDict["sex"])
Answer:
Hands:
0. Try to write a program using the address book properties dictionary bar, function as shown:
me:
print(""" |---欢迎进入通讯录程序---| |---1:查询联系人资料 ---| |---2:插入新的联系人 ---| |---3:删除已有联系人 ---| |---4:退出通讯录程序 ---| """) dictTX=dict() while 1: InputY = int(input("请输入相关的指令代码:")) if InputY == 1: name = input("请输入联系人姓名:") print(name + ":" + dictTX[name]) elif InputY == 2 : name = input("请输入联系人姓名:") if name in dictTX: print("您输入的姓名已经在通讯录中 -->> ",name," : ",dictTX[name]) temp = input("是否需要修改用户资料(YES/NO):") if temp == "YES": namder = input("请输入用户联系电话:") dictTX[name] = namder else: namder = input("请输入用户联系电话:") dictTX[name] = namder elif InputY == 3: name=input("请输入联系人姓名:") if name in dictTX: del dictTX[name] else: print(name,"不在通讯录中;") elif InputY == 4: print("|--- 感谢使用通讯录程序 ---|") break