[Python-ideas] Operator for inserting an element into a list
Serhiy Storchaka
storchaka at gmail.com
Tue Jun 12 11:29:37 EDT 2018
12.06.18 17:54, Mikhail V пише:
> I think it would be logical to have the insert operator for lists.
> Similar to list extend operator += , it could use one of augmented
> assignment operators, e,g, /=.
>
> L = ["aa"]
>
> L[0] /= "bb"
>
> -> ["bb", "aa"]
>
> L[0] /= [1,2]
>
> -> [[1,2], "aa"]
>
> etc.
>
> Without index it would work like append():
>
> L /= "bb"
>
> #-> ["aa", "bb"]
>
>
> As for possible spellings I like this one as well:
>
> L[i] ^= e
>
> The proposed solution is meant to have insert() method semantics,
> plus it would cover append() method nicely.
>
> Insert and append are very frequent operations, so I wonder
> if there was already related suggestion? Is there some technical
> problem with implementing this?
Nice idea for your language.
More information about the Python-ideas
mailing list