[Python-Dev] partition() (was: Remove str.find in 3.0?)

Raymond Hettinger raymond.hettinger at verizon.net
Tue Aug 30 20:25:17 CEST 2005

[Ron Adam]
> This would allow creating an iterator that could iterate though a
> splitting on each sep from either the left, or right.

For uses more complex than basic partitioning, people should shift to
more powerful tools like re.finditer(), re.findall(), and re.split().

> I can't think of an obvious use for a partition iterator at the
> maybe someone could find an example.

I prefer to avoid variants that are searching of a purpose.

> In any case, finding the second,
> or third sep is probably common enough.

That case should be handled with consecutive partitions:

# keep everything after the second 'X'
head, found, s = s.partition('X')
head, found, s = s.partition('x')


More information about the Python-Dev mailing list