[Python-ideas] unicodedata.itergraphemes (or str.itergraphemes / str.graphemes)
Joshua Landau
joshua at landau.ws
Wed Jul 10 01:40:27 CEST 2013
On 10 July 2013 00:15, David Kendal <me at dpk.io> wrote:
> On 9 Jul 2013, at 17:51, Bruce Leban <bruce at leapyear.org> wrote:
>
>> If you want to do any operation on the clusters other than in iteration
>> order, without indexed access you're going to end up doing
>> list(grapheme_clusters(...)) first to give you indexed access. Maybe that's
>> the right thing to do sometimes but I wouldn't force it on people. The
>> string already provides indexed access but I need to know cluster
>> boundaries.
>
> There's no reason the iterator returned can't be of a new type that allows indexing with the subscript operator.
I've only loosely followed this thread but that sounds like a really
weird idea to me. The standard is to have an object with the
properties you want that can be coerced to an iterator through its
__iter__ method. Maybe that's what you meant, though.
>>> range(133)[32]
32
>>> iter(range(133))[32]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'range_iterator' object is not subscriptable
More information about the Python-ideas
mailing list