Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python move item in list to end

# initializing list
test_list = [3, 5, 7, 9, 11]

# printing original list
print("The original list =", test_list)

# using append() + pop() + index()
# moving element to end
test_list.append(test_list.pop(test_list.index(5)))

# printing result
print("The modified list =", test_list)

# output =
# The original list = [3, 5, 7, 9, 11]
# The modified list = [3, 7, 9, 11, 5]
 
PREVIOUS NEXT
Tagged: #python #move #item #list
ADD COMMENT
Topic
Name
7+3 =