#6.1
person = {"first_name":"Bill","last_name":"Gates","age":61,"city":"Beijing"}
print(person)
for key,value in person.items():
# print("key: " + key)
# print("value:" ,value)
print(key,":",value)
~~~~~~~~~~~~~~~~~~~~~~~~~~
{'first_name': 'Bill', 'last_name': 'Gates', 'age': 61, 'city': 'Beijing'}
first_name : Bill
last_name : Gates
age : 61
city : Beijing
#6.2
nums = {"波哥":3,"波妞":5,"大青":1,"想飞":9,"李白":2}
for k,v in nums.items():
print(k,"喜欢",v)
~~~~~~~~~~~~~~~~~~~~~~~~
波哥 喜欢 3
波妞 喜欢 5
大青 喜欢 1
想飞 喜欢 9
李白 喜欢 2
#6.3
dcts = {"Invoke":"调用","Iteration ":"迭代","Rcursion":"递归","Loop":"循环"}
for key,value in dcts.items():
print(key+"\n" + "\t" + value)
~~~~~~~~~~~~~~~~~~~~~~~~
Invoke
调用
Iteration
迭代
Rcursion
递归
Loop
循环
#6.5
rivers = {"changjiang":"china","nile":"egypt","mississippi ":"america"}
for key,value in rivers.items():
print("The " ,key.title(), "runs through " + value.capitalize())
~~~~~~~~~~~~~~~~~~
The Changjiang runs through China
The Nile runs through Egypt
The Mississippi runs through America
#6.7
man1 = {"first_name":"Bill","last_name":"Gates","age":61,"city":"Beijing"}
man2 = {"first_name":"Jason","last_name":"Willianms","age":21,"city":"NewYork"}
man3 = {"first_name":"Bai","last_name":"Li","age":111,"city":"Hangzhou"}
people = [man1,man2,man3]
for p in people:
print("\n下面是" + p["first_name"] + p["last_name"] + "的信息:")
for key,value in p.items():
print(key + ":",value)
~~~~~~~~~~~~~~~~~~~~~~~~~
下面是BillGates的信息:
first_name: Bill
last_name: Gates
age: 61
city: Beijing
下面是JasonWillianms的信息:
first_name: Jason
last_name: Willianms
age: 21
city: NewYork
下面是BaiLi的信息:
first_name: Bai
last_name: Li
age: 111
city: Hangzhou
#6.8
maomao = {"type":"dog","master":"波哥"}
diudiu = {"type":"cat","master":"波妞"}
pets = [maomao,diudiu]
for pet in pets:
print("\n下面是" + pet["master"] + "宠物的信息:")
for key,value in pet.items():
print(key + ":",value)
~~~~~~~~~~~~~~~~~~~~
下面是波哥宠物的信息:
type: dog
master: 波哥
下面是波妞宠物的信息:
type: cat
master: 波妞
网友评论