#-*-coding:utf-8 -*-
#6-1
person
=
{
'first_name'
:
'Yang'
,
'last_name'
:
'xh'
,
'age'
:
19
,
'city'
:
'Beijing'
}
for
key,value
in
person.items():
print
(value,
end
=
' '
)
#6-2
favorite_number
=
{}
favorite_number[
'xiaojz'
]
=
13
favorite_number[
'Yangxh'
]
=
1
favorite_number[
'Lirui'
]
=
3
favorite_number[
'Wangy'
]
=
6
favorite_number[
'Alice'
]
=
0
#6-3
code_language
=
{
'+'
:
'add'
,
'-'
:
'minus'
,
'if'
:
'如果'
,
'while'
:
'当'
,
'return'
:
'返回'
}
for
i,v
in
code_language.items():
print
(i,
':'
,v)
#6-4
code_language[
'print'
]
=
'打印'
code_language[
'and'
]
=
'与'
code_language[
'or'
]
=
'或者'
code_language[
'not'
]
=
'非'
code_language[
'%'
]
=
'除余'
for
i,v
in
code_language.items():
print
(i,
':'
,v)
#6-5
river
=
{
'The Yellow River'
:
'china'
,
'nile'
:
'egypt'
,
'the Indus River'
:
'India'
}
for
i,v
in
river.items():
print
(i,
'run through'
,v)
for
i
in
river:
print
(i)
for
i
in
river.values():
print
(i)
#6-6
favorite_languages
=
{
'jen'
:
'python'
,
'sarah'
:
'c'
,
'edward'
:
'ruby'
,
'phil'
:
'python'
}
people
=
[
'John'
,
'pepper'
,
'jen'
,
'sarah'
,
'edward'
,
'phil'
]
for
i
in
people:
if
i
in
favorite_languages.keys():
print
(
'thank you'
)
else
:
print
(
'Can you accept our investigation?'
)
#6-7
people
=
[]
person1
=
{
'first_name'
:
'Yang'
,
'last_name'
:
'll'
,
'age'
:
19
,
'city'
:
'Tianjin'
}
person2
=
{
'first_name'
:
'Li'
,
'last_name'
:
'r'
,
'age'
:
19
,
'city'
:
'Beijin'
}
people.append(person)
people.append(person1)
people.append(person2)
for
i
in
people:
for
v,u
in
i.items():
print
(v,
':'
,u)
print
()
#6-8
pets
=
[]
Dust
=
{
'kind'
:
'Crow'
,
'master'
:
'xiao'
}
Maomao
=
{
'kind'
:
'cat'
,
'Master'
:
'li'
}
zhuzhu
=
{
'kind'
:
'pig'
,
'Master'
:
'cheng'
}
pets.append(Dust)
pets.append(Maomao)
pets.append(zhuzhu)
for
i
in
pets:
for
v,u
in
i.items():
print
(v,
':'
,u)
print
()
#6-9
favorite_places
=
{
'xiaojz'
:[
'Beijin'
,
'guangzhou'
,
'gansu'
],
'John'
:[
'shanghai'
,
'xinjiang'
,
'new York'
],
'Jack'
:[
'California'
,
'africa'
,
'brazil'
]}
for
i,v
in
favorite_places.items():
print
(i
+
':'
,
end
=
' '
)
for
u
in
v :
print
(u,
end
=
' '
)
print
()
#6-10
favorite_number
=
{}
favorite_number[
'xiaojz'
]
=
[
13
,
2
,
1
]
favorite_number[
'Yangxh'
]
=
[
1
,
2
,
3
]
favorite_number[
'Lirui'
]
=
[
4
,
5
,
6
]
favorite_number[
'Wangy'
]
=
[
7
,
8
,
9
]
favorite_number[
'Alice'
]
=
[
1
,
2
]
for
i,v
in
favorite_number.items():
print
(i
+
':'
,
end
=
' '
)
for
u
in
v :
print
(u,
end
=
' '
)
print
()
#6-11
cities
=
{}
cities[
'Beijin'
]
=
{
'country'
:
'china'
,
'population'
:
20000000
,
'fact'
:
'policy center'
}
cities[
'shanghai'
]
=
{
'country'
:
'china'
,
'population'
:
24000000
,
'fact'
:
'sea'
}
cities[
'gansu'
]
=
{
'country'
:
'china'
,
'population'
:
26000000
,
'fact'
:
'desert'
}
for
i,v
in
cities.items():
print
(i
+
': '
,
end
=
' '
)
for
a,b
in
v.items():
print
(a
+
':'
,b,
end
=
' '
)
print
()