teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

6

Add expression

2020/08/06 09:14

投稿

y_shinoda
y_shinoda

スコア3272

answer CHANGED
@@ -33,4 +33,14 @@
33
33
 
34
34
  if __name__ == '__main__':
35
35
  main()
36
- ```
36
+ ```
37
+
38
+ 実行結果:
39
+
40
+ ```
41
+ $ python test.py
42
+ []
43
+ ['test', 'test2']
44
+ ```
45
+
46
+ `Allcator.some_condition` を実装すると、振り分けが行えます

5

Fix answer

2020/08/06 09:14

投稿

y_shinoda
y_shinoda

スコア3272

answer CHANGED
@@ -20,7 +20,7 @@
20
20
  else:
21
21
  self.list_allocated_b.append(x)
22
22
 
23
- def some_condition(x):
23
+ def some_condition(self, x):
24
24
  """ここに割り振りの条件を定義して bool 型を返します"""
25
25
 
26
26
  def main():

4

Fix answer

2020/08/06 09:11

投稿

y_shinoda
y_shinoda

スコア3272

answer CHANGED
@@ -15,7 +15,7 @@
15
15
 
16
16
  def allocate(self):
17
17
  for x in self.list_x:
18
- if some_condition(x):
18
+ if self.some_condition(x):
19
19
  self.list_allocated_a.append(x)
20
20
  else:
21
21
  self.list_allocated_b.append(x)

3

Fix code

2020/08/06 08:49

投稿

y_shinoda
y_shinoda

スコア3272

answer CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  ```python
7
7
  class Allcator():
8
- def __init__(self, list_x):
8
+ def __init__(self):
9
9
  self.list_x = []
10
10
  self.list_allocated_a = []
11
11
  self.list_allocated_b = []

2

Fix code

2020/08/06 08:33

投稿

y_shinoda
y_shinoda

スコア3272

answer CHANGED
@@ -15,11 +15,14 @@
15
15
 
16
16
  def allocate(self):
17
17
  for x in self.list_x:
18
- if some_condition():
18
+ if some_condition(x):
19
19
  self.list_allocated_a.append(x)
20
20
  else:
21
21
  self.list_allocated_b.append(x)
22
22
 
23
+ def some_condition(x):
24
+ """ここに割り振りの条件を定義して bool 型を返します"""
25
+
23
26
  def main():
24
27
  allcator = Allcator()
25
28
  allcator.define_list()

1

Fix code

2020/08/06 06:30

投稿

y_shinoda
y_shinoda

スコア3272

answer CHANGED
@@ -24,8 +24,8 @@
24
24
  allcator = Allcator()
25
25
  allcator.define_list()
26
26
  allcator.allocate()
27
- print(self.list_allocated_a)
27
+ print(allcator.list_allocated_a)
28
- print(self.list_allocated_b)
28
+ print(allcator.list_allocated_b)
29
29
 
30
30
 
31
31
  if __name__ == '__main__':