回答編集履歴
2
追記
test
CHANGED
@@ -92,6 +92,8 @@
|
|
92
92
|
|
93
93
|
"""
|
94
94
|
|
95
|
+
```
|
95
96
|
|
96
97
|
|
98
|
+
|
97
|
-
|
99
|
+
数十万件だとそのまま使うのは厳しいかもしれません。うまいやり方を考えるのは他の方に譲ります(あるいはご自身でどうぞ)。
|
1
追記
test
CHANGED
@@ -21,3 +21,77 @@
|
|
21
21
|
['あ', 'い', 'う', 'え', 'お', 'あい', 'いう', 'うえ', 'えお', 'あいう', 'いうえ', 'うえお', 'あいうえ', 'いうえお', 'あいうえお']
|
22
22
|
|
23
23
|
```
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
### 追記
|
28
|
+
|
29
|
+
要求を理解できたので、素直に書いてみました。
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
```python
|
34
|
+
|
35
|
+
from itertools import chain, combinations
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
lst = ["あいう", "あうえ", "い", "うい"]
|
40
|
+
|
41
|
+
def make_combi(s):
|
42
|
+
|
43
|
+
s_set = set(s)
|
44
|
+
|
45
|
+
result = []
|
46
|
+
|
47
|
+
for i in range(len(s_set)):
|
48
|
+
|
49
|
+
result.extend(sorted([tuple(sorted(x)) for x in combinations(s_set, i+1)]))
|
50
|
+
|
51
|
+
return result
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
combi_result = [make_combi(s) for s in lst]
|
56
|
+
|
57
|
+
chained_data = list(chain.from_iterable(combi_result))
|
58
|
+
|
59
|
+
index = sorted(list(set(chained_data)))
|
60
|
+
|
61
|
+
result = [(key, chained_data.count(key)) for key in index]
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
for key, val in result:
|
66
|
+
|
67
|
+
print(key, val)
|
68
|
+
|
69
|
+
"""結果
|
70
|
+
|
71
|
+
('あ',) 2
|
72
|
+
|
73
|
+
('あ', 'い') 1
|
74
|
+
|
75
|
+
('あ', 'い', 'う') 1
|
76
|
+
|
77
|
+
('あ', 'う') 2
|
78
|
+
|
79
|
+
('あ', 'う', 'え') 1
|
80
|
+
|
81
|
+
('あ', 'え') 1
|
82
|
+
|
83
|
+
('い',) 3
|
84
|
+
|
85
|
+
('い', 'う') 2
|
86
|
+
|
87
|
+
('う',) 3
|
88
|
+
|
89
|
+
('う', 'え') 1
|
90
|
+
|
91
|
+
('え',) 1
|
92
|
+
|
93
|
+
"""
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
```
|