回答編集履歴

1

コード修正

2018/04/11 06:01

投稿

can110
can110

スコア38262

test CHANGED
@@ -14,15 +14,13 @@
14
14
 
15
15
  lines = ['あいう','あうえ','い','うい']
16
16
 
17
-
18
-
19
17
  lines = [''.join( sorted(line)) for line in lines]# 文字の並びは関係ないので最初に昇順に
20
18
 
21
19
 
22
20
 
23
21
  combs = {} # キー:各文字列に出現しうる文字の組み合わせ
24
22
 
25
- # 値 :どの文字列で出現したかを記録するマップ。要素数=出現した文字列の
23
+ # 値 :出現した文字列の位置の集合。要素数=出現数
26
24
 
27
25
 
28
26
 
@@ -34,18 +32,16 @@
34
32
 
35
33
  for i in itertools.combinations(line,n+1):
36
34
 
37
- s = ''.join( i)
35
+ if i not in combs:
38
36
 
39
- if s not in combs:
37
+ combs[i] = set()
40
38
 
41
- combs[s] = {}
39
+ combs[i].add(idx)
42
-
43
- combs[s][idx] = 1 # この1という値は適当
44
40
 
45
41
 
46
42
 
47
43
  for k,v in combs.items():
48
44
 
49
- print('({}) ->{}個'.format(k,len(v)))
45
+ print('{} ->{}個'.format(k,len(v)))
50
46
 
51
47
  ```