How to replace sublist with new list in Python

1 Answer

0 votes
def replace_sublist(lst, start, end, new_list):
   return lst[:start] + new_list + lst[end:]

lst = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
new_list = [10, 11, 12]

lst = replace_sublist(lst, 3, 6, new_list)

print(lst)



'''
run:

[0, 1, 2, 10, 11, 12, 6, 7, 8, 9]

'''

 



answered Feb 14 by avibootz
...