[Tutor] lists

Lloyd Kvam pythontutor@venix.com
Fri Jun 6 18:53:01 2003


Do you really need to save list2's (potential) contents?
Yes:
	list2.append(list1[:])	# copy from list1 to list2
	del list1[:]		# del contents of list1

[:] grabs a slice from a list.  If nothing else is specified, the slice is a copy
of the whole list.  list1[-5:] would grab the last 5 items as a slice of list1.

No:
	list2 = list1	# assign list2's name to list1
	del list1[:]	

********

The del statement for list1 covers the case where you have other names bound
to list1 and ALL of those names should now be bound to the same empty list.

list1 = [] #would leave the other names bound to list1 with contents.

Vidhya Narayanan wrote:
> Hi,
> 
>     I have this very basic question. I have two lists. I deleted some items from
> list1. list 2 is empty. I need to move the remaining items from list1 to list 2
> in the same order. Can some one help me out ?Thanks in advance
> 
> best
> Vidhya
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 


-- 
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice:	603-443-6155
fax:	801-459-9582