a possibly foolish question about slices
holger krekel
pyth at devel.trillke.net
Mon Jun 17 04:47:37 EDT 2002
Garth T Kidd wrote:
> > x[p:][:n]
>
> Does the parser take the appropriate short-cut, here, or do we end up
> with a temporary list?
the parser looks at syntax rather than semantics. You probably mean the
compiler or bytecode-generator. This is the roughly the bytecode:
>>> f=lambda x: x[3:][:7]
>>> import dis
>>> dis.dis(f)
0 SET_LINENO 1
3 LOAD_FAST 0 (x)
6 LOAD_CONST 1 (3)
9 SLICE+1
10 LOAD_CONST 2 (7)
13 SLICE+2
14 RETURN_VALUE
The SLICE+1 outcome/sideeffects cannot be predicted by the compiler,
so he simply does what you say.
regards,
holger
More information about the Python-list
mailing list