INSERT()

The insert() method allows you to add a new item at a specific position within a list. You provide both the index where the element should be placed and the element itself. Existing items at and after that index are shifted one position to the right to make space for the new entry.

colors = ['red', 'green', 'blue']
input1, input2 = input.split()
colors.insert(0, input1)
colors.insert(2, input2)
print(colors)

Last updated