WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   deleting elements inside a list problem (https://forum.worldviz.com/showthread.php?t=1818)

nlfrnassimi 02-12-2009 11:40 PM

deleting elements inside a list problem
 
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/diveintopyt...lper_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:

Code:


list = [a,b,c,f,d,h,y]

del list[:] # Deletes all elements

print list # Check all items have been removed



All times are GMT -7. The time now is 03:07 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC