> On 2018 Jun 12 , at 10:54 a, Mikhail V <mikhail...@gmail.com> wrote: > > 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"]
-1. There's not much about this that is logical, no matter how much you want an insertion operator. Even if L[0] /= "bb" worked, then logically so should L[0] = L[0] / "bb". However, there is no sense in which L[0] / "bb" by itself has any meaning, and what would L[1] = L[0] / "bb" mean? And finally, L[0] /= x (and really, every other augmented operator) *already has* a meaning: >>> L = [10] >>> L[0] /= 2 >>> L [5] > > Note that there is a trick to 'insert' an element with slicing syntax, e.g.: > > L[0:0] = [[1,2]] > > -> [[1,2], "aa"] > > > L[0:0] = ["bb"] > > -> ["bb", "aa"] > > The trick is to put brackets around the element and so it works as insert(). > Though additional brackets look really confusing for this purpose, so I don't > feel like using this seriously. It's no more confusing than co-opting an unrelated operator to do the same thing. -- Clint _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/