Use the list methods, pop(), insert() and append()
list1 = [54, 44, 27, 79, 91, 41]
List After removing element at index 4 [34, 54, 67, 89, 43, 94] List after Adding element at index 2 [34, 54, 11, 67, 89, 43, 94] List after Adding element at last [34, 54, 11, 67, 89, 43, 94, 11]
sample_list = [34, 54, 67, 89, 11, 43, 94]
print("Original list ", sample_list)
element = sample_list.pop(4)
print("List After removing element at index 4 ", sample_list)
sample_list.insert(2, element)
print("List after Adding element at index 2 ", sample_list)
sample_list.append(element)
print("List after Adding element at last ", sample_list)
Original list [34, 54, 67, 89, 11, 43, 94]
List After removing element at index 4 [34, 54, 67, 89, 43, 94]
List after Adding element at index 2 [34, 54, 11, 67, 89, 43, 94]
List after Adding element at last [34, 54, 11, 67, 89, 43, 94, 11]
pop(index): Removes and returns the item at the given index from the list.insert(index, item): Add the item at the specified position(index) in the listappend(item): Add item at the end of the list.First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.
Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.
Sign in to save your progress and continue exactly where you left off.