On Fri, Mar 05, 2021 at 04:27:27PM -0000, Vincent Cheong wrote:

> Currently, list.reverse() only works for an entire list. If one wants 
> to reverse a section of it 'in-place', one needs to slicing which 
> makes the space complexity no longer O(1).

The space complexity of a list is not constant, O(1).

The lists [] and [1]*100000 do not take the same amount of space.

I think that, perhaps, you are trying to say that reversing a list 
requires no additional storage and can be done in place. 

But having said that, I think that giving `list.reverse()` optional 
start and end parameters would probably be a simple and easy change to 
make, and would be backwards compatible.

But even easy changes have some cost: the work has to be done, tests 
written and run, documentation updated, and that adds one more thing for 
people to learn. To balance those costs, we require something more than 
"Wouldn't it be good...?", we require an actual, real life use-case for 
the feature. (And even then, it's not a guarantee that we will accept 
the proposed feature.)

1. What are you doing that you need to reverse just a section of 
   the list?

2. Is the performance (time or space) of this task so critical
   that you can't just use slicing?

    mylist[start:end] = mylist[end-1:start-1:-1]


Some additional questions:

- Do we extend this feature to the `reversed()` built-in?

- What about sorting?


-- 
Steve
_______________________________________________
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/G7UYGVXJQV23L7IKJUQMJJB63OMXDBG5/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to