回答編集履歴
2
追記
answer
CHANGED
@@ -45,5 +45,6 @@
|
|
45
45
|
('う', 'え') 1
|
46
46
|
('え',) 1
|
47
47
|
"""
|
48
|
+
```
|
48
49
|
|
49
|
-
|
50
|
+
数十万件だとそのまま使うのは厳しいかもしれません。うまいやり方を考えるのは他の方に譲ります(あるいはご自身でどうぞ)。
|
1
追記
answer
CHANGED
@@ -9,4 +9,41 @@
|
|
9
9
|
...
|
10
10
|
>>> lst
|
11
11
|
['あ', 'い', 'う', 'え', 'お', 'あい', 'いう', 'うえ', 'えお', 'あいう', 'いうえ', 'うえお', 'あいうえ', 'いうえお', 'あいうえお']
|
12
|
+
```
|
13
|
+
|
14
|
+
### 追記
|
15
|
+
要求を理解できたので、素直に書いてみました。
|
16
|
+
|
17
|
+
```python
|
18
|
+
from itertools import chain, combinations
|
19
|
+
|
20
|
+
lst = ["あいう", "あうえ", "い", "うい"]
|
21
|
+
def make_combi(s):
|
22
|
+
s_set = set(s)
|
23
|
+
result = []
|
24
|
+
for i in range(len(s_set)):
|
25
|
+
result.extend(sorted([tuple(sorted(x)) for x in combinations(s_set, i+1)]))
|
26
|
+
return result
|
27
|
+
|
28
|
+
combi_result = [make_combi(s) for s in lst]
|
29
|
+
chained_data = list(chain.from_iterable(combi_result))
|
30
|
+
index = sorted(list(set(chained_data)))
|
31
|
+
result = [(key, chained_data.count(key)) for key in index]
|
32
|
+
|
33
|
+
for key, val in result:
|
34
|
+
print(key, val)
|
35
|
+
"""結果
|
36
|
+
('あ',) 2
|
37
|
+
('あ', 'い') 1
|
38
|
+
('あ', 'い', 'う') 1
|
39
|
+
('あ', 'う') 2
|
40
|
+
('あ', 'う', 'え') 1
|
41
|
+
('あ', 'え') 1
|
42
|
+
('い',) 3
|
43
|
+
('い', 'う') 2
|
44
|
+
('う',) 3
|
45
|
+
('う', 'え') 1
|
46
|
+
('え',) 1
|
47
|
+
"""
|
48
|
+
|
12
49
|
```
|