a possibly foolish question about slices

John La Rooy larooy at xtar.co.nz
Sun Jun 16 03:02:40 EDT 2002


On Fri, 14 Jun 2002 17:50:09 GMT
Andrew Koenig <ark at research.att.com> wrote:

> Suppose x is a string or list, and I want to refer to
> a subsequence of x with length n starting at position p.
> under the assumption that this subsequence is entirely
> 
> To do so, I can use x[p:p+n] in all circumstances but one,
> namely when p < 0 and p == -n.  Is there a similarly concise
> expression that works even in this special case?
> 
> -- 
> Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark

x[p:][:n]

John



More information about the Python-list mailing list