View Full Version : deleting elements inside a list problem
nlfrnassimi
02-12-2009, 11:40 PM
how can I remove all the elements inside a list?
DrunkenBrit
02-12-2009, 11:48 PM
If it's a simple python related question (and not specifically Vizard) you should try googling your questions first, 90% of the time you'll fine the answer :)
I Googled "Lists - Python" turned up:
http://www.faqs.org/docs/diveintopython/odbchelper_list.html
Scroll down the page and you'll fine your answer.
nlfrnassimi
02-12-2009, 11:56 PM
thanks, but i need to know how to remove all the elements with one code. For example I have a list:
list = [a,b,c,f,d,h,y]
and i want to write a code to delete from first element to last. I can't find any code.
DrunkenBrit
02-13-2009, 12:16 AM
I google searched again and came across this: http://effbot.org/zone/python-list.htm
It covers what you need to know :) If you're working with lists I suggest you read it.
To delete all elements in a list you use a slice like so:
list = [a,b,c,f,d,h,y]
del list[:] # Deletes all elements
print list # Check all items have been removed
vBulletin® v3.8.7, Copyright ©2000-2024, vBulletin Solutions, Inc.