【发布时间】:2018-07-21 21:47:09
【问题描述】:
我正在尝试将给定的字符串(“hello”)转换为包含每个子字符串列表的列表。例如:
[["hello"],["h,"ello"],["he","llo"],["hel","lo"],["hell","o"],\
["h","e","llo"],["h","e","l","lo"],["h","e","l","l","o],["he","l,"lo"],\
["hel","l,"o"],["hell","o]....etc....].
我知道最快的方法应该是递归函数,但我就是做错了。 类似于:
x = "hello"
wordset=[]
string_div(0,x,wordset)
...
...
def string_div(i,word,wordset)
wordset.append(wordset+[word[i:])
......
【问题讨论】:
标签: python string list if-statement substring