[Python-ideas] Operator for inserting an element into a list

Mikhail V mikhailwas at gmail.com
Sun Jun 17 07:43:16 EDT 2018

On Sun, Jun 17, 2018 at 2:52 AM, Steven D'Aprano <steve at pearwood.info> wrote:
> On Sat, Jun 16, 2018 at 08:21:42PM +0300, Mikhail V wrote:

>> By L[] there is some mnemonical hint because [] is used to create
>> new empty list.
> How is that a hint? What is the connection between "append an item" and
> "create a new empty list"?

Where did I say it has _direct_ connection?
It has some associative connection - 'new item',  'special index case'.
L = [] is new list which is supposed to be filled with something.

And it has references to existing syntax, e.g. slice assignment, or
adding dictionary item can be written as :

mydict[key] = value

mylist[] = item

is not THAT far. I would even say it's very close - but I'm pretty
sure you can find something against this as well.

> Here is a radical thought... why don't we give lists a method that
> inserts items at the end of the list? We could call it something like
> "append", and then instead of hoping people guess what the syntax does,
> they can just look up the name of the method?
> L.append(x)

Exercising in wit?

How about: let's assume most people can't understand even the simplest
new feature.
So instead of giving clean compact assignment syntax for frequent operation,
let's force less readable method call everywhere,
which also might be harder to remember than one index case [].


Maybe force .extend() for lists and .update() for dicts everywhere?
To preserve poor new users from 'unintuitive' assignment syntax.
But how you would do that?

More information about the Python-ideas mailing list