回答編集履歴

6

Add expression

2020/08/06 09:14

投稿

y_shinoda
y_shinoda

スコア3272

test CHANGED
@@ -69,3 +69,23 @@
69
69
  main()
70
70
 
71
71
  ```
72
+
73
+
74
+
75
+ 実行結果:
76
+
77
+
78
+
79
+ ```
80
+
81
+ $ python test.py
82
+
83
+ []
84
+
85
+ ['test', 'test2']
86
+
87
+ ```
88
+
89
+
90
+
91
+ `Allcator.some_condition` を実装すると、振り分けが行えます

5

Fix answer

2020/08/06 09:14

投稿

y_shinoda
y_shinoda

スコア3272

test CHANGED
@@ -42,7 +42,7 @@
42
42
 
43
43
 
44
44
 
45
- def some_condition(x):
45
+ def some_condition(self, x):
46
46
 
47
47
  """ここに割り振りの条件を定義して bool 型を返します"""
48
48
 

4

Fix answer

2020/08/06 09:11

投稿

y_shinoda
y_shinoda

スコア3272

test CHANGED
@@ -32,7 +32,7 @@
32
32
 
33
33
  for x in self.list_x:
34
34
 
35
- if some_condition(x):
35
+ if self.some_condition(x):
36
36
 
37
37
  self.list_allocated_a.append(x)
38
38
 

3

Fix code

2020/08/06 08:49

投稿

y_shinoda
y_shinoda

スコア3272

test CHANGED
@@ -12,7 +12,7 @@
12
12
 
13
13
  class Allcator():
14
14
 
15
- def __init__(self, list_x):
15
+ def __init__(self):
16
16
 
17
17
  self.list_x = []
18
18
 

2

Fix code

2020/08/06 08:33

投稿

y_shinoda
y_shinoda

スコア3272

test CHANGED
@@ -32,13 +32,19 @@
32
32
 
33
33
  for x in self.list_x:
34
34
 
35
- if some_condition():
35
+ if some_condition(x):
36
36
 
37
37
  self.list_allocated_a.append(x)
38
38
 
39
39
  else:
40
40
 
41
41
  self.list_allocated_b.append(x)
42
+
43
+
44
+
45
+ def some_condition(x):
46
+
47
+ """ここに割り振りの条件を定義して bool 型を返します"""
42
48
 
43
49
 
44
50
 

1

Fix code

2020/08/06 06:30

投稿

y_shinoda
y_shinoda

スコア3272

test CHANGED
@@ -50,9 +50,9 @@
50
50
 
51
51
  allcator.allocate()
52
52
 
53
- print(self.list_allocated_a)
53
+ print(allcator.list_allocated_a)
54
54
 
55
- print(self.list_allocated_b)
55
+ print(allcator.list_allocated_b)
56
56
 
57
57
 
58
58