a possibly foolish question about slices
Martin v. Loewis
martin at v.loewis.de
Fri Jun 14 14:54:46 EDT 2002
Andrew Koenig <ark at research.att.com> writes:
> 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
... within the boundaries?
> 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?
Perhaps not concise, but compact:
x[p:p+n or sys.maxint]
Regards,
Martin
More information about the Python-list
mailing list