#6.1 people
infos = {'first_name':'Airous',
'last_name':'Wang',
'age':'28',
'city':'Beijin'
}
print(infos["first_name"])
print(infos['last_name'])
print(infos['age'])
print(infos['city'])
#6.2 favorite numbers
list_of_people = {'benji':'12', 'airous':'6', 'ricky':'15', 'simone':'18', 'karl':'42'}
print(list_of_people['airous'])
print(list_of_people['benji'])
print(list_of_people['ricky'])
print(list_of_people['simone'])
print(list_of_people['karl'])
#6.3 vocabulary form
meanings = {'append':'the way that insert an element to the end of the list or tuple',
'list':'a group of elements together, all of which is changeable',
'tuple':'similar as list but the elements cannot be changed unless you redefine'
}
print(meanings)
user_0 = {
'username': 'efermi',
'first': 'enrico',
'last': 'fermi',
}
for key, value in user_0.items():
print("\nKey: " + key)
print("Value: " + value)
#6.4 vocabulary form 2
meanings = {'append':'the way that insert an element to the end of the list or tuple',
'list':'a group of elements together, all of which is changeable',
'tuple':'similar as list but the elements cannot be changed unless you redefine'
}
for key, value in meanings.items():
print("\nKey: " + key.title())
print("Value: " + value)
#6.5 rivers
rivers = {'nile':'egypt',
'yellow river':'china',
'mississippi':'america'
}
for k, v in rivers.items():
print("The " + k.title() + " runs through " + v.title())
for name in rivers.keys():
print("Name: " + name.title())
for country in rivers.values():
print("Country: " + country.title())
#6.6 inspection
favorite_languages = {
'jen': 'python',
'sarah': 'c',
'edward': 'ruby',
'phil': 'python',
}
list_of_inspection = ['jen', 'sarah', 'benji', 'phil']
for name in favorite_languages.keys():
if name in list_of_inspection:
print(name.title() + ", thank you for helping us!")
else:
print(name.title() + ", please help us to inspect.")
#6.7 people
infos = {"Airous": {'first name': 'Airous', 'last name':'Wang', 'age':'28', 'city':'Beijin'},
"Benji": {'first name': 'Benji', 'last name':'He', 'age':'28', 'city':'Shenzhen'},
"Ricky": {'first name': 'Ricky', 'last name':'Mak', 'age':'60', 'city':'Shenzhen'}
}
for name, info in infos.items():
print("First name: " + name.title() +
"\nLast name: " + info['last name'] +
"\nAge: " + info["age"]+
"\nCity: " + info['city'] + "\n"
)
#6.8 pets
puppy = {'type':'retriever',
'master':'Benji'}
cat = {'type':'chinese li hua',
'master':'ricky'}
parrot = {'type':'howl',
'master':'leo'}
pets = [puppy,cat,parrot]
for info in pets:
print(info)
#6.9 places people like
favorite_places = {'Benji':['New York', 'Iceland', 'Glasgow'],
'Ricky':['Hong Kong', 'Shenzhen', 'London'],
'Karl':['Shanghai', 'Pari', 'Huston']
}
for name, places in favorite_places.items():
print("\nName: " + name.title())
print("Favorite Places are: ")
for p in places:
print(str(p))
#6.10
#skip it as its similarity.
#6.11 cities
cities = {'shenzhen':{'country':'china', 'population':'8 millions', 'fact':'young city'},
'hong kong':{'country':'china', 'population':'7 millions', 'fact':'crowd city'},
'beijin':{'country':'china', 'population':'10 millions', 'fact':'biggest city'}
}
for city, information in cities.items():
print("\nName of City: " + city.title())
print("Informations of City: " +
"\n\tCountry: " + information['country'].title() +
"\n\tPopulation: " + information['population'].title() +
"\n\tFact: " + information['fact'].title()
)
#6.12
#skip it.