Slices time complexity
Mario Figueiredo
marfig at gmail.com
Mon May 18 15:23:37 EDT 2015
I'd like to understand what I'm being told about slices in
https://wiki.python.org/moin/TimeComplexity
Particularly, what's a 'del slice' and a 'set slice' and whether this
information pertains to both CPython 2.7 and 3.4.
>From the above link it seems slices work in linear time on all cases.
And this really has a big impact on certain operations. For instance,
the code below may surprise some people when they realize it doesn't
run in linear time on 3.4:
def minimum(values):
if len(values) == 1:
return values[0]
else:
m = minimum(values[1:])
return m if m < values[0] else values[0]
Other languages implement slices. I'm currently being faced with a Go
snippet that mirrors the exact code above and it does run in linear
time.
Is there any reason why Python 3.4 implementation of slices cannot be
a near constant operation?
More information about the Python-list
mailing list