[Python-ideas] Alternative spelling for list.append()
rosuav at gmail.com
Mon Jun 18 16:03:05 EDT 2018
On Tue, Jun 19, 2018 at 5:51 AM, Mikhail V <mikhailwas at gmail.com> wrote:
> On Mon, Jun 18, 2018 at 4:12 AM, Chris Angelico <rosuav at gmail.com> wrote:
>> On Mon, Jun 18, 2018 at 10:50 AM, Steven D'Aprano <steve at pearwood.info> wrote:
>>>>> items[-0:] # failed parallel
>> ['spam', 'ham', 'foo', 'bar', 'quux']
>> So you use -1 in slices to parallel 1 (unlike using ~1 as with
>> indexing), and everything works *except zero*. Which means that the
>> slice-assignment form of insert is easy to write, but the
>> slice-assignment form of append isn't.
>> Mikhail, if it were possible to append using slice assignment, would
>> that meet the case?
> How? like this:
> items[-0:] = [item]
Well, yes, except for the part where -0 is indistinguishable from 0.
> One of main motivation is actually to have just 'item' on the right side.
> So your idea is to have special syntax for 'last item' so as to avoid
> something like:
> c = len(L)
> L[c:c] = [...]
> But IIUC you're still about _iterable_ on the right-hand part?
Yes, for consistency with other slice assignment. I don't think a
dedicated syntax for slotting a single item into it has any chance of
being accepted. (PLEASE NOTE: I am not Guido. ) But
I'm trying to find some germ of an idea inside what you're asking for,
something that IS plausible.
More information about the Python-ideas