質問編集履歴
4
test
CHANGED
File without changes
|
test
CHANGED
@@ -60,7 +60,7 @@
|
|
60
60
|
|
61
61
|
- 与えられる辞書に含まれる`unnecessary_keys`以外のkeyは一つか二つである事が多いです。(つまり`sample_dict`のような物が多い)
|
62
62
|
|
63
|
-
- `unnecessary_keys`は上に書いた内容で常に固定されています。
|
63
|
+
- ~~`unnecessary_keys`は上に書いた内容で常に固定されています。~~ 除きたいkeyは上に書いた6つで固定されています。
|
64
64
|
|
65
65
|
|
66
66
|
|
@@ -78,7 +78,7 @@
|
|
78
78
|
|
79
79
|
|
80
80
|
|
81
|
-
得られた回答を元に以下の
|
81
|
+
得られた回答を元に以下の6つも比較対象に加えた結果
|
82
82
|
|
83
83
|
|
84
84
|
|
3
比較結果の更新
test
CHANGED
File without changes
|
test
CHANGED
@@ -128,7 +128,7 @@
|
|
128
128
|
|
129
129
|
def method_4a(d):
|
130
130
|
|
131
|
-
'''ppaulさんのmethod_4
|
131
|
+
'''ppaulさんのmethod_4'''
|
132
132
|
|
133
133
|
d = d.copy()
|
134
134
|
|
@@ -178,25 +178,41 @@
|
|
178
178
|
|
179
179
|
return d
|
180
180
|
|
181
|
+
|
182
|
+
|
183
|
+
def method_6(d):
|
184
|
+
|
185
|
+
'''quickquipさんの方法'''
|
186
|
+
|
187
|
+
d = d.copy()
|
188
|
+
|
189
|
+
for key in intersection(d):
|
190
|
+
|
191
|
+
del d[key]
|
192
|
+
|
193
|
+
return d
|
194
|
+
|
181
|
-
```
|
195
|
+
```
|
182
|
-
|
183
|
-
|
184
|
-
|
196
|
+
|
197
|
+
|
198
|
+
|
185
|
-
```
|
199
|
+
```
|
186
|
-
|
200
|
+
|
187
|
-
1 :
|
201
|
+
1 : 6.086940804998449
|
188
|
-
|
202
|
+
|
189
|
-
2 : 7.
|
203
|
+
2 : 7.495010836995789
|
190
|
-
|
204
|
+
|
191
|
-
3a: 5.22
|
205
|
+
3a: 5.200945402000798
|
192
|
-
|
206
|
+
|
193
|
-
3b: 5.04
|
207
|
+
3b: 5.059846481999557
|
194
|
-
|
195
|
-
|
208
|
+
|
196
|
-
|
197
|
-
4
|
209
|
+
4a: 5.46594832399569
|
210
|
+
|
198
|
-
|
211
|
+
4b: 5.468696205003653
|
212
|
+
|
199
|
-
5 : 5.1
|
213
|
+
5 : 5.198188450005546
|
214
|
+
|
215
|
+
6 : 4.907909608999034
|
200
216
|
|
201
217
|
```
|
202
218
|
|
@@ -206,12 +222,14 @@
|
|
206
222
|
|
207
223
|
|
208
224
|
|
225
|
+
1. `method_6`
|
226
|
+
|
209
227
|
1. `method_3b`と`method_5` (順位は不安定。`method_3b`の方が速いことが多い)
|
210
228
|
|
211
|
-
|
229
|
+
1. `method_3a`
|
212
|
-
|
230
|
+
|
213
|
-
|
231
|
+
1. `method_4a`と`method_4b` (順位は不安定)
|
214
|
-
|
232
|
+
|
215
|
-
|
233
|
+
1. `method_1`
|
216
|
-
|
234
|
+
|
217
|
-
|
235
|
+
1. `method_2`
|
2
回答を元に比較結果を更新
test
CHANGED
File without changes
|
test
CHANGED
@@ -78,7 +78,7 @@
|
|
78
78
|
|
79
79
|
|
80
80
|
|
81
|
-
|
81
|
+
得られた回答を元に以下の5つも比較対象に加えた結果
|
82
82
|
|
83
83
|
|
84
84
|
|
@@ -94,6 +94,8 @@
|
|
94
94
|
|
95
95
|
def method_3a(d):
|
96
96
|
|
97
|
+
'''ppaulさんのmethod_3に少し手を加えた物'''
|
98
|
+
|
97
99
|
d = d.copy()
|
98
100
|
|
99
101
|
for key in intersection(d):
|
@@ -108,6 +110,8 @@
|
|
108
110
|
|
109
111
|
def method_3b(d):
|
110
112
|
|
113
|
+
'''method_3aの'd.__delitem__'をloopの外に出した物'''
|
114
|
+
|
111
115
|
d = d.copy()
|
112
116
|
|
113
117
|
delitem = d.__delitem__
|
@@ -124,6 +128,8 @@
|
|
124
128
|
|
125
129
|
def method_4a(d):
|
126
130
|
|
131
|
+
'''ppaulさんのmethod_4に少し手を加えた物'''
|
132
|
+
|
127
133
|
d = d.copy()
|
128
134
|
|
129
135
|
for key in unnecessary_keys:
|
@@ -140,6 +146,8 @@
|
|
140
146
|
|
141
147
|
def method_4b(d):
|
142
148
|
|
149
|
+
'''method_4aの'd.__delitem__'をloopの外に出した物'''
|
150
|
+
|
143
151
|
d = d.copy()
|
144
152
|
|
145
153
|
delitem = d.__delitem__
|
@@ -152,28 +160,58 @@
|
|
152
160
|
|
153
161
|
return d
|
154
162
|
|
163
|
+
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
def method_5(d):
|
168
|
+
|
169
|
+
'''quickquipさんの方法'''
|
170
|
+
|
171
|
+
d = d.copy()
|
172
|
+
|
173
|
+
for key in unnecessary_keys:
|
174
|
+
|
175
|
+
if key in d:
|
176
|
+
|
177
|
+
del d[key]
|
178
|
+
|
179
|
+
return d
|
180
|
+
|
155
|
-
```
|
181
|
+
```
|
156
|
-
|
157
|
-
|
158
|
-
|
182
|
+
|
183
|
+
|
184
|
+
|
159
|
-
```
|
185
|
+
```
|
160
|
-
|
186
|
+
|
161
|
-
1 : 5.
|
187
|
+
1 : 5.916446945004282
|
162
|
-
|
188
|
+
|
163
|
-
2 : 7.
|
189
|
+
2 : 7.3307233180021285
|
164
|
-
|
190
|
+
|
165
|
-
3a: 5.18
|
191
|
+
3a: 5.222118170997419
|
166
|
-
|
192
|
+
|
167
|
-
3b: 5.
|
193
|
+
3b: 5.047232527002052
|
194
|
+
|
168
|
-
|
195
|
+
4a: 5.437795748002827
|
196
|
+
|
169
|
-
4
|
197
|
+
4b: 5.435121403999801
|
170
|
-
|
198
|
+
|
171
|
-
|
199
|
+
5 : 5.131977698998526
|
172
|
-
|
200
|
+
|
173
|
-
```
|
201
|
+
```
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
202
|
+
|
178
|
-
|
203
|
+
|
204
|
+
|
179
|
-
[code全体](https://gist.github.com/gottadiveintopython/04fce1af28eb66d1053ff191f5b616ce)
|
205
|
+
以下の順となりました。[code全体](https://gist.github.com/gottadiveintopython/04fce1af28eb66d1053ff191f5b616ce)
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
1. `method_3b`と`method_5` (順位は不安定。`method_3b`の方が速いことが多い)
|
210
|
+
|
211
|
+
2. `method_3a`
|
212
|
+
|
213
|
+
3. `method_4a`と`method_4b` (順位は不安定)
|
214
|
+
|
215
|
+
4. `method_1`
|
216
|
+
|
217
|
+
5. `method_2`
|
1
教えてもらった方法との比較結果を追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -71,3 +71,109 @@
|
|
71
71
|
|
72
72
|
|
73
73
|
CPython 3.7.1
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
# 追記
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
ppaulさんの回答を元に以下の4つも比較対象に加えた所
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
```
|
86
|
+
|
87
|
+
unnecessary_keys = ('s', 'd', 't', 'step', 'duration', 'transition', )
|
88
|
+
|
89
|
+
intersection = set(unnecessary_keys).intersection
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
def method_3a(d):
|
96
|
+
|
97
|
+
d = d.copy()
|
98
|
+
|
99
|
+
for key in intersection(d):
|
100
|
+
|
101
|
+
d.__delitem__(key)
|
102
|
+
|
103
|
+
return d
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
def method_3b(d):
|
110
|
+
|
111
|
+
d = d.copy()
|
112
|
+
|
113
|
+
delitem = d.__delitem__
|
114
|
+
|
115
|
+
for key in intersection(d):
|
116
|
+
|
117
|
+
delitem(key)
|
118
|
+
|
119
|
+
return d
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
def method_4a(d):
|
126
|
+
|
127
|
+
d = d.copy()
|
128
|
+
|
129
|
+
for key in unnecessary_keys:
|
130
|
+
|
131
|
+
if key in d:
|
132
|
+
|
133
|
+
d.__delitem__(key)
|
134
|
+
|
135
|
+
return d
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
def method_4b(d):
|
142
|
+
|
143
|
+
d = d.copy()
|
144
|
+
|
145
|
+
delitem = d.__delitem__
|
146
|
+
|
147
|
+
for key in unnecessary_keys:
|
148
|
+
|
149
|
+
if key in d:
|
150
|
+
|
151
|
+
delitem(key)
|
152
|
+
|
153
|
+
return d
|
154
|
+
|
155
|
+
```
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
```
|
160
|
+
|
161
|
+
1 : 5.862659796002845
|
162
|
+
|
163
|
+
2 : 7.536483085001237
|
164
|
+
|
165
|
+
3a: 5.1854341859943816
|
166
|
+
|
167
|
+
3b: 5.132281307000085
|
168
|
+
|
169
|
+
4a: 5.413436234994151
|
170
|
+
|
171
|
+
4b: 5.490977667999687
|
172
|
+
|
173
|
+
```
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
`method_3b` -> `method_3a` -> `method_4a`と`method_4b` -> `method_1` -> `method_2` の順になりました。(`method_4a`と`method_4b`の順位は安定せず)
|
178
|
+
|
179
|
+
[code全体](https://gist.github.com/gottadiveintopython/04fce1af28eb66d1053ff191f5b616ce)
|