6-1 6-4
myfriend = {'first_name': 'niok', 'last_name': 'yhg', 'age': 18,
'city':'xian'}
print(myfriend)
print('\n')
for key, value in myfriend.items():
print(key + ":")
print(value)
print('\n')
6-6
names = ['csd', 'fdae', 'saw', 'vcbdfr', 'oiuy']
dic = {'csd': 'python', 'saw': 'C', 'oiuy': 'C++'}
for name in names:
if name in dic.keys():
print(name.title() + ", Thanks for attending us!")
else:
print(name.title() + ", We hope you can join us!")
6-8
pets = {'sijia': {'species': 'dog', 'owner': 'anxuefeng'},
'siling': {'species': 'dog', 'owner': 'wangbaicai'},
'nemo': {'species': 'cat', 'owner': 'dalian'},
'saner': {'species': 'cat', 'owner': 'daodao'},}
for key, value in pets.items():
print(key + " is a " + value['species'] + ".")
print("He's owner is " + value['owner'] + ".")
print("\n")