在Python中,我想为列表中的每个字符串添加一个空格。结果与字符串或列表无关。但是我想得到字符串中可以有空格的所有情况的数目。你知道吗
首先,我试着这样做,使字符串列表。你知道吗
sent = 'apple is good for health'
sent.split(' ')
sentence = []
b = ''
for i in sent:
c = ''
for j in sent[(sent.index(i)):]:
c += j
sentence.append((b+' '+c).strip())
b += i
sentence
在这种情况下,结果将获得仅包含一个空格的字符串。你知道吗
我也试过了
for i in range(len(sent)):
sent[i:i] = [' ']
另一个尝试是' '.join(sent[i:])
但结果是一样的。你知道吗
我怎样才能得到
'apple isgoodforhealth', 'appleis goodforhealth', 'appleisgood forhealth', 'appleisgoodfor health', 'appleis goodfor health', 'apple isgood forhealth', 'appleisgood forhealth' ...
这样地?你知道吗
我真的想得到所有病例的数目。你知道吗
使用加入:-
我对这个问题的看法是利用itertools.combinations。你知道吗
相关问题 更多 >
编程相关推荐