回答編集履歴
2
修正
test
CHANGED
@@ -1 +1,37 @@
|
|
1
|
-
|
1
|
+
いちおうこんな感じで可能ではあります。
|
2
|
+
|
3
|
+
```Python
|
4
|
+
|
5
|
+
from itertools import chain
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
tmp = []
|
10
|
+
|
11
|
+
a = ['1', '2', '3', '10', '5']
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
key_index = 3
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
num_a = [int(e) for e in a]
|
20
|
+
|
21
|
+
cond2 = all(e < 10 for e in chain(num_a[:key_index], num_a[key_index+1:]))
|
22
|
+
|
23
|
+
if num_a[key_index] >= 10 and cond2:
|
24
|
+
|
25
|
+
tmp.append(a[key_index])
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
print(tmp)
|
30
|
+
|
31
|
+
```
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
ただし、そもそも**a[3]だけ特別な役割を持っているのが謎**です。
|
36
|
+
|
37
|
+
それならばリストよりも、辞書や[namedtuple](https://docs.python.jp/3/library/collections.html#collections.namedtuple)などを用いた方が良いような。
|
1
修正
test
CHANGED
@@ -1,21 +1 @@
|
|
1
|
-
```Python
|
2
|
-
|
3
|
-
|
1
|
+
誤爆したので修正します。少々お待ちください。
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
tmp=[]
|
8
|
-
|
9
|
-
a = ['1', '2', '3', '10', '5']
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
num_a = [int(e) for e in a]
|
14
|
-
|
15
|
-
cond2 = all(e < 10 for e in chain(num_a[:3], num_a[3+1:]))
|
16
|
-
|
17
|
-
if num_a[3] >= 10 and cond2:
|
18
|
-
|
19
|
-
tmp.append(a[3])
|
20
|
-
|
21
|
-
```
|