Re: adding a character to the last string element of a list

2005-07-06 Thread Philippe C. Martin
Thanks, Philippe Peter Hansen wrote: > Philippe C. Martin wrote: >> I guess my slicing was wrong, l[-1] worked > > Note that that's _not_ a slice, however, but a reference to the last > element in the list. > > You'd have to subclass list to be able to do something with > "reference-slices".

Re: adding a character to the last string element of a list

2005-07-06 Thread Peter Hansen
Philippe C. Martin wrote: > I guess my slicing was wrong, l[-1] worked Note that that's _not_ a slice, however, but a reference to the last element in the list. You'd have to subclass list to be able to do something with "reference-slices". Probably returning a special object from __getslice_

RE: adding a character to the last string element of a list

2005-07-05 Thread Philippe C. Martin
I guess my slicing was wrong, l[-1] worked Regards, Philippe -- http://mail.python.org/mailman/listinfo/python-list

Re: adding a character to the last string element of a list

2005-07-05 Thread Philippe C. Martin
Thanks, I though it was a reference (tough to implement I'm sure) Regards, Philippe Peter Hansen wrote: > Philippe C. Martin wrote: >> l = ['ABCDE','FGHI'] > > Okay so far... > >> l[1:] #returns ['FGHI'] > > Which is a _copy_ (via slicing) of part of the list. Another way of > saying this

Re: adding a character to the last string element of a list

2005-07-05 Thread Peter Hansen
Philippe C. Martin wrote: > l = ['ABCDE','FGHI'] Okay so far... > l[1:] #returns ['FGHI'] Which is a _copy_ (via slicing) of part of the list. Another way of saying this is that it is a _new_ list which has a copy of the references from the appropriate part of the old list. Try "l[1:] is l[1

adding a character to the last string element of a list

2005-07-05 Thread Philippe C. Martin
Hi, I have the following question: l = ['ABCDE','FGHI'] l[1:] #returns ['FGHI'] l[1:][0] #return 'FGHI' a = l[1:][0] + 'J' #a becomes 'FGHIJ' l[1:][0] += 'J' #NO ERROR BUT l[1:][0] == 'FGHI' What am I missing ? Thanks, Philippe -- http://mail.python.org/mailman/listinfo/python-list