回答編集履歴
2
d
test
CHANGED
@@ -15,3 +15,27 @@
|
|
15
15
|
print(lst) # [{'価格': 100, '商品': 'りんご'}, {'価格': 200, '商品': 'ぶどう'}, {'価格': 150, '商品': 'バナナ'}]
|
16
16
|
|
17
17
|
```
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
上記処理は以下と同じです。
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
```python
|
26
|
+
|
27
|
+
list_name = ["りんご", "ぶどう", "バナナ"]
|
28
|
+
|
29
|
+
list_price = [100, 200, 150]
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
lst = []
|
34
|
+
|
35
|
+
for price, name in zip(list_price, list_name):
|
36
|
+
|
37
|
+
lst.append({"価格": price, "商品": name})
|
38
|
+
|
39
|
+
print(lst)
|
40
|
+
|
41
|
+
```
|
1
d
test
CHANGED
@@ -10,12 +10,8 @@
|
|
10
10
|
|
11
11
|
|
12
12
|
|
13
|
-
lst = [{"価格": price, "商品": name} for
|
13
|
+
lst = [{"価格": price, "商品": name} for price, name in zip(list_price, list_name)]
|
14
14
|
|
15
15
|
print(lst) # [{'価格': 100, '商品': 'りんご'}, {'価格': 200, '商品': 'ぶどう'}, {'価格': 150, '商品': 'バナナ'}]
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
17
|
```
|