#首先使用enumerate生成一个有索引和可迭代对象的元素组成的一个枚举对象,使用lst_index记录上一次分隔符的位置,注意最后一组元素
def my_split(s,separator=" "):
new_lst=[]
lst_index=0
for index,char in enumerate(s):
if char==separator:
new_lst.append(s[lst_index:index])
lst_index=index
[python每日一练]split-使用enumerate来实现split方法
最新推荐文章于 2023-09-22 15:50:22 发布