On 2021-03-05 at 16:27:27 -0000, Vincent Cheong <vincentcheong6...@gmail.com> 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). One can also manually make > a loop and do the reversal but that is even slower than > slicing. List.reverse() does not take any arguments. Wouldn't it be a > good if it can take in parameters such as 'start' and 'stop' to enable > list.reverse() work even for a section of the list? When no arguments > are specified, then it works on the whole list, like usual. Try this: def slice_reverse(the_list, start, stop): the_list[start:stop] = the_list[stop - 1, start - 1, -1] I'll defer on whether or not this deserves a place in the standard library; the older I get, the more I prefer building new data than mutating existing data. _______________________________________________ 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/DWV7DH3H7MIWQXMI2A5C5GAW4CYLSNDI/ Code of Conduct: http://python.org/psf/codeofconduct/