Why doesn't python's list append() method return the list itself?

dhruvbird dhruvbird at gmail.com
Mon Jul 12 15:24:29 EDT 2010


On Jul 12, 4:20 pm, Hrvoje Niksic <hnik... at xemacs.org> wrote:
> dhruvbird <dhruvb... at gmail.com> writes:
> > No, I meant x.append(4)
> > Except that I want to accomplish it using slices.
>
> > (I can do it as x[lex(x):] = [item_to_append] but is there any other
> > way?)
>
> It seems that you've found a way to do so, so why do you need another
> way?  Are you after elegance?  Efficiency?  Brevity?

Actually, the reason I ask is because I think a lot of things can be
done using slices and its support for negative indexes. Basically
putting constants in the slices (as opposed to variables like len(x),
etc... which depend upon the variable name). So, was just trying to
cogitate on whether append can be implemented that way or not.

Regards,
-Dhruv.



More information about the Python-list mailing list