所属作业: hw5
数据结构: 字典
算法: 循环
提示:
dict.get(key,default=None) 返回字典中key对应的值,如果不存在,返回default的值
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| friends = {}
while True:
line = input()
if line == 'e':
break
elif line[0] == 'a':
friend, address = line.split()[1:]
friends[friend] = address
elif line[0] == 'q':
friend = line.split()[1]
**if friend in friends:
print(friends[friend])
else:
print("Not found!")**
|
1
| **print(friends.get(friend, 'Not found!'))**
|