質問編集履歴

3

検証したことの追加

2018/03/02 12:44

投稿

mofu_mofu
mofu_mofu

スコア73

test CHANGED
File without changes
test CHANGED
@@ -30,7 +30,11 @@
30
30
 
31
31
 
32
32
 
33
- →dictってindex付けられないんじゃないの?index付けられないのにkeyだと[0]で指定できてvalueだと[1]なの???と思ってしまいます。例えば、
33
+ →dictってindex付けられないんじゃないの?index付けられないのにkeyだと[0]で指定できてvalueだと[1]なの???と思ってしまいます。
34
+
35
+
36
+
37
+ 例えば、
34
38
 
35
39
 
36
40
 
@@ -62,6 +66,38 @@
62
66
 
63
67
 
64
68
 
69
+ (追記)
70
+
71
+
72
+
73
+
74
+
75
+ items()の返り値がtupleになるから???
76
+
77
+
78
+
79
+ ```
80
+
81
+ >>>("A",100)
82
+
83
+ ('A', 100)
84
+
85
+ >>>("A",100)[0]
86
+
87
+ 'A'
88
+
89
+ >>>("A",100)[1]
90
+
91
+ 100
92
+
93
+
94
+
95
+ ```
96
+
97
+
98
+
99
+
100
+
65
101
  ②```key=lambda x: x[1]```だと昇順になるがこの```x[1]```にマイナスをつけると昇順から降順に変わるのはなぜか
66
102
 
67
103
 

2

実行環境の明示

2018/03/02 12:44

投稿

mofu_mofu
mofu_mofu

スコア73

test CHANGED
File without changes
test CHANGED
@@ -72,6 +72,16 @@
72
72
 
73
73
 
74
74
 
75
+ ###実行環境
76
+
77
+ Python3.6
78
+
79
+ Mac High Sierra 10.13.3
80
+
81
+
82
+
83
+
84
+
75
85
 
76
86
 
77
87
 

1

内容の順番を変えた

2018/03/02 12:38

投稿

mofu_mofu
mofu_mofu

スコア73

test CHANGED
File without changes
test CHANGED
@@ -3,6 +3,26 @@
3
3
 
4
4
 
5
5
  yukicoderでPythonを使って[この問題](https://yukicoder.me/problems/no/570)を[解いた](https://yukicoder.me/submissions/240376)のですが、解く際にdict型を使ったほうがいいと思ったので[Python sortのまとめ (リスト、辞書型、Series、DataFrame)](https://qiita.com/shizuma/items/40f1fe4702608db40ac3#value%E6%98%87%E9%A0%86%E3%82%BD%E3%83%BC%E3%83%88)というqiitaの記事を参考にしましたが、気になる点が2点ありました。
6
+
7
+
8
+
9
+ ```
10
+
11
+ #私の書いたコード(https://yukicoder.me/submissions/240376)
12
+
13
+
14
+
15
+ height_dict = {"A":int(input()),"B":int(input()),"C":int(input())}
16
+
17
+
18
+
19
+ for k,v in sorted(height_dict.items(), key=lambda x:-x[1]):
20
+
21
+ print(k)
22
+
23
+ ```
24
+
25
+
6
26
 
7
27
 
8
28
 
@@ -54,22 +74,6 @@
54
74
 
55
75
 
56
76
 
57
- ```
58
-
59
- #私の書いたコード(https://yukicoder.me/submissions/240376)
60
-
61
-
62
-
63
- height_dict = {"A":int(input()),"B":int(input()),"C":int(input())}
64
-
65
-
66
-
67
- for k,v in sorted(height_dict.items(), key=lambda x:-x[1]):
68
-
69
- print(k)
70
-
71
- ```
72
-
73
77
 
74
78
 
75
79
  以上よろしくお願いいたします。