Answers for "how to remove last 2 elements from list in python"

8

remove last element from list python

>>> l = list(range(1,5))
>>> l
[1, 2, 3, 4]
>>> l.pop()
4
>>> l
[1, 2, 3]
Posted by: Guest on May-05-2020
1

delete last few items from a list python

# Remove the last 3 items from a list
x = [1, 2, 3, 4, 5]
for i in range(3): x.pop()
Posted by: Guest on June-19-2021
0

how to remove last 2 elements from list in python

l = list(range(1,5))
l = test_list[: len(test_list) - 2]
Posted by: Guest on August-27-2020

Code answers related to "how to remove last 2 elements from list in python"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language