-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path33. Nested List (List Bersarang).py
More file actions
156 lines (32 loc) · 1.36 KB
/
33. Nested List (List Bersarang).py
File metadata and controls
156 lines (32 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# Nested List/List Bersarang
print("\n" + "=" * 10 + "Nested List/List Bersarang" + "=" * 10 + "\n")
data_0 = [1,2]
data_1 = [3,4,5]
data_list_biasa = [1,2,3,4]
print(f"List biasa = {data_list_biasa}")
list_2D = [data_0,data_1]
print(f"List 2D = {list_2D}")
list_2D = [data_0,data_1,data_list_biasa]
print(f"List 2D = {list_2D}")
list_2D = [data_0,data_1,6,7] # Campuran antara List dan Angka
print(f"List 2D = {list_2D}")
# Nested List digunakan untuk Data Berseri
# Contoh Penggunaan
print("\n" + "=" * 3 + "Contoh Pengunaan" + "=" * 3)
peserta_0 = ["Ucup",25,"Laki-laki"]
peserta_1 = ["Otong",10,"Laki-laki"]
peserta_2 = ["Dedeh",50,"Wanita"]
list_peserta = [peserta_0,peserta_1,peserta_2]
print(f"Peserta = {list_peserta}\n")
for peserta in list_peserta:
print(f"Nama\t = {peserta[0]}")
print(f"Umur\t = {peserta[1]}")
print(f"Gender\t = {peserta[2]}\n")
# Dengan Reference
print("\n" + "=" * 3 + "Dengan Reference" + "=" * 3)
list_copy = list_peserta.copy()
print(f"Peserta = {list_copy}\n")
peserta_0[0] = "Michael"
print(f"Peserta = {list_copy}\n")
print(f"Peserta = {list_peserta}\n")
print("\n")