以一定分隔符的字符串重复的实现,关键在于如何排除末尾的分隔符:
def repeat(what, count, separator):
return ((what + separator)*count)[:-len(separator)]
当然也可以这样:
def repeat(what, count, separator):
return what + (separator + what)*count
以一定分隔符的字符串重复的实现,关键在于如何排除末尾的分隔符:
def repeat(what, count, separator):
return ((what + separator)*count)[:-len(separator)]
当然也可以这样:
def repeat(what, count, separator):
return what + (separator + what)*count