[Python-3000] Making more effective use of slice objects in Py3k
Nick Coghlan
ncoghlan at gmail.com
Sat Aug 26 11:40:19 CEST 2006
Nick Coghlan wrote:
A couple of errors in the sample code.
> The new method would have semantics like:
>
> def partition_indices(self, sep, limits=None):
> if limits is None:
> limits = range(0, len(self))
> else:
> limits = limits.indices(len(self))
Either that line should be:
limits = range(*limits.indices(len(self)))
Or the definition of indices() would need to be changed to return a range()
object instead of a 3-tuple.
> For comparison, here's the normal copying version that has problems scaling to
> large strings:
>
> def splitpartition(s):
> rest = s
> while 1:
> prefix, lbrace, rest = rest.partition_indices("{")
> first, space, rest = rest.partition_indices(" ")
> second, rbrace, rest = rest.partition_indices("}")
Those 3 lines should be:
prefix, lbrace, rest = rest.partition("{")
first, space, rest = rest.partition(" ")
second, rbrace, rest = rest.partition("}")
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
http://www.boredomandlaziness.org
More information about the Python-3000
mailing list