如何从字符串中删除指定范围?
该函数应该接受一个字符串和索引列表,并返回一个新字符串,其中删除了这些索引之间的字符。
论据:
my_str (str): The string to be modified.
ranges (list): A list of [start, end] indices.
假设 start 和 end 都是有效的索引(ie. between 0 and len(my_str), inclusive),并且start <= end. 假设范围从最早到最晚排序(ie. [0, 10] will come before [15, 20]),并且范围不会重叠。
我不知道如何开始,关键是不要使用del语句
例子:
word = "white laptop"
indices = [9, 11]
print(remove_range(word, indices)
>>> white lap