6-1:
friend
= {
'
first_name
':
'
YIngxue
',
'
last_name
':
'
Zheng
',
'
age
':
20,
'
city
':
'
Hefei
'}
print
(friend)
6-2:
numbers
= {
'
Alan
':
1,
'
Mary
':
2,
'
John
':
3,
'
James
':
4,
'
Jay
':
5}
print
(
'
Alan
'
, numbers[
'
Alan
'
])
print
(
'
Mary
'
, numbers[
'
Mary
'
])
print
(
'
John
'
, numbers[
'
John
'
])
print
(
'
James
'
, numbers[
'
James
'
])
print
(
'
Jay
'
, numbers[
'
Jay
'
])
6-3:
vo
= {
'
del
':
'
删除
',
'
lower()
':
'
将所有字母小写
',
'
upper()
':
'
将所有字母大写
',
'
append()
':
'
添加一个元素
',
'
print()
':
'
输出函数
'
}
for key, value
in vo.
items
():
print
(key
+
'
:
'
, value)
6-5:
rivers
= {
'
Nile
':
'
Egyt
',
'
Rhine
':
'
France
',
'
Yellow River
':
'
China
'}
for key, value
in rivers.
items
():
print
(
'
The
'
, key,
'
runs through
'
, value)
for key
in rivers.
keys
():
print
(key)
for value
in rivers.
values
():
print
(value)
6-6:
favorite_languages
= {
'
jen
':
'
python
',
'
sarah
':
'
c
',
'
edward
':
'
ruby
',
'
phil
':
'
python
',
}
someones
=
[
'
jen
',
'
sarah
',
'
phil
',
'
jay
',
'
john
',
'
alan
'
]
for person
in someones:
if person
in favorite_languages.
keys
():
print
(person,
'
谢谢你的参与!
'
)
else:
print
(person,
'
希望你也能参与!
'
)
6-7:
friend1
= {
'
first_name
':
'
YIngxue
',
'
last_name
':
'
Zheng
',
'
age
':
20,
'
city
':
'
Hefei
'}
friend2
= {
'
first_name
':
'
Xinrui
',
'
last_name
':
'
Li
',
'
age
':
19,
'
city
':
'
Guangzhou
'}
friend3
= {
'
first_name
':
'
Jie
',
'
last_name
':
'
Zong
',
'
age
':
20,
'
city
':
'
Guangzhou
'}
people
=
[friend1, friend2, friend3
]
for person
in people:
for key, value
in person.
items
():
print
(key,
'
:
'
, value,
end
=
'
'
)
print
(
'
\n
'
)
6-9:
favorite_places
= {
'
Alan
':
[
'
Shanghai
',
'
Guangzhou
',
'
Shanxi
'
],
'
John
':
[
'
Beijing
',
'
Wuhan
',
'
Changsha
'
],
'
Mary
':
[
'
Hefei
',
'
Shijiazhuang
',
'
Nanjing
'
]
}
for key, places
in favorite_places.
items
():
print
(key,
'
want to go to
'
,
end
=
'
'
)
for place
in places:
print
(place,
end
=
'
'
)
print
()
6-10:
numbers
= {
'
Alan
':
[
1,
2,
3,
4,
5
],
'
Mary
':
[
6,
7,
8,
9,
10
],
'
John
':
[
11,
12,
13,
14,
15
],
'
James
':
[
16,
17,
18,
19,
20
],
'
Jay
':
[
21,
22,
23,
24,
25
]
}
for key, places
in numbers.
items
():
print
(key,
'
like
'
,
end
=
'
'
)
for place
in places:
print
(place,
end
=
'
'
)
print
()
6-11:
cities
= {
'
Beijing
': {
'
nation
':
'
China
',
'
population
':
10000000,
'
fact
':
'
中国的首都
'
},
'
Guangzhou
': {
'
nation
':
'
China
',
'
population
':
10000000,
'
fact
':
'
位于中国南部
'
},
'
Hefei
': {
'
nation
':
'
China
',
'
population
':
10000000,
'
fact
':
'
位于中国中部
'
}
}
for city, info
in cities.
items
():
print
(city,
'
:
'
)
for key, value
in info.
items
():
print
(
'
\t
'
, key,
'
:
'
, value)