【发布时间】:2011-07-16 15:03:31
【问题描述】:
我有一组字符串,例如
my_prefix_what_ever
my_prefix_what_so_ever
my_prefix_doesnt_matter
我只是想找到这些字符串中最长的公共部分,这里是前缀。在上面的结果应该是
my_prefix_
字符串
my_prefix_what_ever
my_prefix_what_so_ever
my_doesnt_matter
应该是前缀
my_
在 Python 中是否有一种相对轻松的方式来确定前缀(无需手动迭代每个字符)?
PS:我使用的是 Python 2.6.3。
【问题讨论】:
-
所以您实际上是在要求 longest common subsequence?