我有字符串,每个字符串都是某个字符串的一个或多个副本。例如:
L = "hellohellohello"
M = "good"
N = "wherewhere"
O = "antant"
我想把这样的字符串拆分成一个列表,这样每个元素只包含重复的部分。例如:
^{pr2}$
由于每个字符串大约有1000个字符长,所以如果速度也相当快的话,那就太好了。在
注意,在我的例子中,重复都是从字符串的开头开始的,它们之间没有间隔,所以这比在字符串中寻找最大重复次数的一般问题简单得多。在
怎么能做到这一点?在
Tags:
使用regex查找重复单词,然后简单地创建一个适当长度的列表:
我将采用的方法是:
使用相应的变量给出以下输出:
^{pr2}$试试这个。它不是剪切列表,而是集中精力寻找最短的模式,然后通过重复这个模式适当的次数来创建一个新的列表。在
相关问题 更多 >
编程相关推荐