Slices time complexity

Serhiy Storchaka storchaka at gmail.com
Tue May 19 15:51:10 EDT 2015


On 19.05.15 18:15, Ian Kelly wrote:
> On May 19, 2015 4:16 AM, "Serhiy Storchaka" <storchaka at gmail.com
> <mailto:storchaka at gmail.com>> wrote:
>  >
>  > On 19.05.15 12:45, Steven D'Aprano wrote:
>  >>
>  >> On Tuesday 19 May 2015 05:23, Mario Figueiredo wrote:
>  >>>
>  >>>  From the above link it seems slices work in linear time on all cases.
>  >>
>  >>
>  >> I wouldn't trust that is always the case, e.g. deleting a contiguous
> slice
>  >> from the end of a list could be O(1).
>  >
>  >
>  > It always has linear complexity. You need to decref removed elements.
>
> Only in CPython. The operation might be O(1) in Pypy or Jython.

In any case you need linear time to free all objects.




More information about the Python-list mailing list