Marco Mariani wrote: > Ricardo Aráoz ha scritto: > >> L = ['one', 'two', 'three', 'four', 'five'] >> >> print L[0] # This would be 'head' >> print L[1:] # This would be 'tail' >> >> Caution : L[0] and L[1:] are COPIES of the head and tail of the list. > > This might surprise people who see L[1:] = [], since changing a copy is > not supposed to change the original.
That's because slicing and assigning is not the same thing as slicing alone. Slicing and assigning mutates the sequence. Slicing alone returns a copy. >>> L = ['one', 'two', 'three', 'four', 'five'] >>> x = L[1:] # grab a slice >>> x[:] = [] # mutate it >>> x [] >>> L # original list is unchanged ['one', 'two', 'three', 'four', 'five'] -- Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/ San Jose, CA, USA && 37 20 N 121 53 W && AIM, Y!M erikmaxfrancis Eternity is very long, especially near the end. -- Woody Allen -- http://mail.python.org/mailman/listinfo/python-list