Python> list> delete last insertion> del somelist [-1]> somelist.pop () / help ([]. Pop).

@ Introducing Python: Modern Computing in Simple Packages by Bill Lubanovic (No. 1270 / 12833)

Let's undo that last insertion:

>>> del marxes[-1]

I implemented it. http://ideone.com/yRBduB

TodoList = []
print(TodoList)

TodoList.append('Futon')
TodoList.append('Monitor desk')
TodoList.append('Internet')
TodoList.append('Electronic Line')
TodoList.append('Water Line')
TodoList.append('Gas Line')
TodoList.append('etc')

print(TodoList)

for loop in range(6):
	del TodoList[-1]
print(TodoList)

Execution result


Success	time: 0.01 memory: 9992 signal:0
[]
['Futon', 'Monitor desk', 'Internet', 'Electronic Line', 'Water Line', 'Gas Line', 'etc']
['Futon']

Additional learning items

@ shiracamus's Comment told me pop () and help ([]. Pop). ..

Thank you for the information.

Recommended Posts

Python> list> delete last insertion> del somelist [-1]> somelist.pop () / help ([]. Pop).
Python> list> pop ()> Get index {specified / unspecified} + del ()
Delete multiple elements in python list