回答編集履歴
1
コード修正
answer
CHANGED
@@ -6,21 +6,19 @@
|
|
6
6
|
import itertools
|
7
7
|
|
8
8
|
lines = ['あいう','あうえ','い','うい']
|
9
|
-
|
10
9
|
lines = [''.join( sorted(line)) for line in lines]# 文字の並びは関係ないので最初に昇順に
|
11
10
|
|
12
11
|
combs = {} # キー:各文字列に出現しうる文字の組み合わせ
|
13
|
-
# 値 :
|
12
|
+
# 値 :出現した文字列の位置の集合。要素数=出現数
|
14
13
|
|
15
14
|
for idx, line in enumerate( lines):
|
16
15
|
# N文字から 1...N文字でできる組み合わせ
|
17
16
|
for n in range(len(line)):
|
18
17
|
for i in itertools.combinations(line,n+1):
|
19
|
-
s = ''.join( i)
|
20
|
-
if
|
18
|
+
if i not in combs:
|
21
|
-
combs[
|
19
|
+
combs[i] = set()
|
22
|
-
combs[
|
20
|
+
combs[i].add(idx)
|
23
21
|
|
24
22
|
for k,v in combs.items():
|
25
|
-
print('
|
23
|
+
print('{} ->{}個'.format(k,len(v)))
|
26
24
|
```
|