06.03.21 09:52, Vincent Cheong пише:
> I see. I do agree that my reply brings about that 'verbose repeated' feeling, 
> haha. But for the record, it's not about having something in hand now for the 
> future, but it's more of a paradigmatic approach to the implementation. 
> Python has changed for the better in terms of necessity:
> 
> - map() returns an iterator instead of a whole list at once
> - generator yields values only when needed (unlike list comprehension)
> 
> So I thought, 'Why do we need to make a reversed copy to assign it to the 
> original part, when we can simply reverse the original part itself.' That's 
> the paradigm.

Your proposition is not related to changes in map() and other builtins
which return now an iterator instead of list. It is more similar to idea
of adding parameters start and stop to map(), so it could be appplied to
a part of the list.

More general approach would allow you to write

    a[i:j] = a[i:j][::-1]

and it would be a zero-overhead operation because slices are lazy or
because the compiler recognize the pattern and generate the optimal
code. But it requires a sophisticate compiler.

Less sophisticate approach is using an explicit wrapper for lazy slices:

    a[i:j] = view(a)[i:j][::-1]

_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/P4BJYONTRZWSC7YWFLAFVOG35FQOQNV2/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to