how to clear up a List in python?

vbgunz vbgunz at gmail.com
Thu May 25 10:26:18 EDT 2006


> I have new a list , when it hava large number of values, I wonna to
> delete all the values in it,how to do?

something like this will probably help.

x = [1,2,3,4,5,6,7,8,9]
y = x

list([x.pop() for z in xrange(len(x))])

print x, y  # [] []

> And, if a list have 801 values, I want to get its values index from 300
> to 400, could use list1[300:400],are right me?

300 will be included in your slice whereas the 400th index will be
excluded. you will ultimately have 99 items in your slice. if you want
values from index 300 to 400 you'll need to say [300:401]. the first
index is included. the last index is excluded.

good luck!




More information about the Python-list mailing list