我有一个字符串,例如“streemlocalbbv”
我有我的_函数,它接受这个字符串和我想在原始字符串中找到的字符串(“loc”)。我想要得到的回报是这个
my_function("streemlocalbbv", "loc")
output = ["streem","loc","albbv"]
到目前为止我所做的是
def find_split(string,find_word):
length = len(string)
find_word_start_index = string.find(find_word)
find_word_end_index = find_word_start_index + len(find_word)
string[find_word_start_index:find_word_end_index]
a = string[0:find_word_start_index]
b = string[find_word_start_index:find_word_end_index]
c = string[find_word_end_index:length]
return [a,b,c]
尝试在原始字符串中查找我要查找的字符串的索引,然后拆分原始字符串。但是从这里我不知道我该怎么做
使用
split, index and insert
函数来解决此问题您可以使用
str.partition
,它完全满足您的需要:使用
split
函数:相关问题 更多 >
编程相关推荐