· 4 years ago · Sep 20, 2021, 02:17 PM
1# 1
2print("***** 1 *****")
3people = [
4 {
5 "Name" : "Anto",
6 "Age" : "15",
7 "Hobby" : "Football"
8 },
9 {
10 "Name" : "Budi",
11 "Age" : "20",
12 "Hobby" : "Coding"
13 },
14 {
15 "Name" : "Charlie",
16 "Age" : "12",
17 "Hobby" : "Gaming"
18 }
19]
20
21for person in people :
22 print(person["Name"])
23 print(f"Age : {person['Age']}")
24 print(f"Hobby : {person['Hobby']}")
25 print()
26
27
28# 2
29print("***** 2 *****")
30pets = [
31 {
32 "typeOfPet" : "Dog",
33 "ownersName" : "Angelice",
34 "breed" : "Chihuahua",
35 "color": "Black"
36 },
37 {
38 "typeOfPet" : "Cat",
39 "ownersName" : "Broody",
40 "breed" : "Anggora",
41 "color": "White"
42 },
43 {
44 "typeOfPet" : "Dog",
45 "ownersName" : "Charlie",
46 "breed" : "Bulldog",
47 "color": "Brown"
48 },
49 {
50 "typeOfPet" : "Cat",
51 "ownersName" : "Dudes",
52 "breed" : "Persian",
53 "color": "Gray"
54 }
55]
56
57for pet in pets :
58 for key, val in pet.items() :
59 print(f"{key.title()} \t: {val.title()}")
60 print()
61
62# 3
63print("***** 3 *****")
64cities = {
65 "Jakarta" : {
66 "Population" : 10560000,
67 "FunFact" : "Memiliki stasiun kereta api terbesar se-ASEAN"
68 },
69 "Palembang" : {
70 "Population" : 1600000,
71 "FunFact" : "Merupakan kota tertua di Indonesia"
72 }
73}
74for city in cities :
75 print(city)
76 for key, val in cities[city].items() :
77 print(f"{key} \t: {val}")
78 print()