import itertools
ws=[]
subs=[]
set_subs=[]
for i in xrange(int(raw_input())):
S=raw_input()
l=len(S)
subs.append(S[i:j+1] for i in xrange(l) for j in xrange(i,l))
input:
2
aab
aac
now both subs[0]
and subs[1]
give me same result.
print list(subs[0])
>>>['a','aa','aac','a','ac','c']
print list(subs[1])
>>>['a','aa','aac','a','ac','c']
whereas list(subs[0])
should have been ['a','aa','aab','a','ab','b']
I vaguely understand why this is happening. What do I do to make subs[0]
and subs[1]
actually different.
NOTE: changing the line
subs.append(S[i:j+1] for i in xrange(l) for j in xrange(i,l))
with
subs.append([S[i:j+1] for i in xrange(l) for j in xrange(i,l)])
is not an option
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…