回答編集履歴
2
コード修正
test
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
|
5
|
-
```
|
5
|
+
```Python
|
6
6
|
|
7
7
|
import re
|
8
8
|
|
@@ -48,7 +48,7 @@
|
|
48
48
|
|
49
49
|
|
50
50
|
|
51
|
-
def count_ch
|
51
|
+
def count_matching(charset, words):
|
52
52
|
|
53
53
|
return (charset, len(list(filter(match_andpattern(charset), words))))
|
54
54
|
|
@@ -60,7 +60,7 @@
|
|
60
60
|
|
61
61
|
charset_list = make_charsets(words)
|
62
62
|
|
63
|
-
count_list = [count_ch
|
63
|
+
count_list = [count_matching(charset, words) for charset in charset_list]
|
64
64
|
|
65
65
|
after = list(map(print, filter(lambda x: x[1] != 0, count_list)))
|
66
66
|
|
1
修正
test
CHANGED
@@ -1 +1,67 @@
|
|
1
|
-
reでANDま
|
1
|
+
reでANDマッチングしてみました。
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
``` python
|
6
|
+
|
7
|
+
import re
|
8
|
+
|
9
|
+
from itertools import combinations
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
def make_charsets(words):
|
16
|
+
|
17
|
+
chars = sorted(set(''.join(words)))
|
18
|
+
|
19
|
+
charset_map = [
|
20
|
+
|
21
|
+
list(combinations(chars, i))
|
22
|
+
|
23
|
+
for i in range(1, len(chars) + 1)
|
24
|
+
|
25
|
+
]
|
26
|
+
|
27
|
+
return [charset for line in charset_map for charset in line]
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
def match_andpattern(charset):
|
34
|
+
|
35
|
+
andpattern = '^' + ''.join(['(?=.*' + c + ')' for c in charset])
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
def _match(word):
|
40
|
+
|
41
|
+
return re.match(andpattern, word) != None
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
return _match
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
def count_charset(charset, words):
|
52
|
+
|
53
|
+
return (charset, len(list(filter(match_andpattern(charset), words))))
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
words = ["あいう", "あうえ", "い", "うい"]
|
60
|
+
|
61
|
+
charset_list = make_charsets(words)
|
62
|
+
|
63
|
+
count_list = [count_charset(charset, words) for charset in charset_list]
|
64
|
+
|
65
|
+
after = list(map(print, filter(lambda x: x[1] != 0, count_list)))
|
66
|
+
|
67
|
+
```
|