回答編集履歴
3
test
CHANGED
@@ -1,12 +1,18 @@
|
|
1
1
|
```python
|
2
2
|
import csv
|
3
|
+
from pprint import pprint
|
3
4
|
|
4
5
|
array = ["Japan", "America", "France"]
|
5
6
|
lst = {0: {0: "France", 1: "Japan", 2: "America"},
|
6
7
|
1: {0: "fraise", 1: "ichigo", 2: "strawberry"}}
|
7
8
|
|
8
|
-
idx = sorted(lst[0], key=lambda k: array.index(lst[0][k]))
|
9
|
+
idx = [*enumerate(sorted(lst[0], key=lambda k: array.index(lst[0][k])))]
|
9
|
-
output =
|
10
|
+
output = {k: {i: v[j] for i, j in idx} for k, v in lst.items()}
|
11
|
+
pprint(output)
|
12
|
+
|
13
|
+
# {0: {0: 'Japan', 1: 'America', 2: 'France'},
|
14
|
+
# 1: {0: 'ichigo', 1: 'strawberry', 2: 'fraise'}}
|
15
|
+
|
10
16
|
with open('output.csv', 'w') as f:
|
11
|
-
csv.writer(f).writerows(output)
|
17
|
+
csv.writer(f).writerows(v.values() for v in output.values())
|
12
18
|
```
|
2
test
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
1: {0: "fraise", 1: "ichigo", 2: "strawberry"}}
|
7
7
|
|
8
8
|
idx = sorted(lst[0], key=lambda k: array.index(lst[0][k]))
|
9
|
-
output = [[v[i] for i in idx] for
|
9
|
+
output = [[v[i] for i in idx] for v in lst.values()]
|
10
10
|
with open('output.csv', 'w') as f:
|
11
11
|
csv.writer(f).writerows(output)
|
12
12
|
```
|
1
test
CHANGED
@@ -5,9 +5,8 @@
|
|
5
5
|
lst = {0: {0: "France", 1: "Japan", 2: "America"},
|
6
6
|
1: {0: "fraise", 1: "ichigo", 2: "strawberry"}}
|
7
7
|
|
8
|
-
idx =
|
8
|
+
idx = sorted(lst[0], key=lambda k: array.index(lst[0][k]))
|
9
|
-
output = [[v[
|
9
|
+
output = [[v[i] for i in idx] for k, v in lst.items()]
|
10
|
-
|
11
10
|
with open('output.csv', 'w') as f:
|
12
11
|
csv.writer(f).writerows(output)
|
13
12
|
```
|