回答編集履歴
3
変数名変更
test
CHANGED
@@ -28,7 +28,7 @@
|
|
28
28
|
|
29
29
|
```python
|
30
30
|
|
31
|
-
b_sorted=[b for a, b in sorted(zip(a_list, b_list), key=lambda
|
31
|
+
b_sorted=[b for a, b in sorted(zip(a_list, b_list), key=lambda ab: ab[0], reverse=True)]
|
32
32
|
|
33
33
|
print(b_sorted)
|
34
34
|
|
2
aの値だけでソートする例を追記
test
CHANGED
@@ -17,3 +17,27 @@
|
|
17
17
|
['f', 'e', 'a', 'b', 'c', 'd']
|
18
18
|
|
19
19
|
```
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
上記はbの値も影響してしまいます。
|
24
|
+
|
25
|
+
aの値だけでソートするならkeyを指定した方がいいですね。
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
```python
|
30
|
+
|
31
|
+
b_sorted=[b for a, b in sorted(zip(a_list, b_list), key=lambda z: z[0], reverse=True)]
|
32
|
+
|
33
|
+
print(b_sorted)
|
34
|
+
|
35
|
+
```
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
```
|
40
|
+
|
41
|
+
['f', 'a', 'e', 'b', 'c', 'd']
|
42
|
+
|
43
|
+
```
|
1
降順に変更
test
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
```python
|
6
6
|
|
7
|
-
b_sorted=[b for a, b in sorted(zip(a_list, b_list))]
|
7
|
+
b_sorted=[b for a, b in sorted(zip(a_list, b_list), reverse=True)]
|
8
8
|
|
9
9
|
print(b_sorted)
|
10
10
|
|
@@ -14,6 +14,6 @@
|
|
14
14
|
|
15
15
|
```
|
16
16
|
|
17
|
-
['
|
17
|
+
['f', 'e', 'a', 'b', 'c', 'd']
|
18
18
|
|
19
19
|
```
|