[Python-ideas] strings as iterables - from str.startswith taking any iterator instead of just tuple
spir
denis.spir at gmail.com
Fri Jan 3 17:39:15 CET 2014
On 01/03/2014 03:39 PM, Nick Coghlan wrote:
> Here, the distinction is between true containers types like sets,
> dicts and lists, and more structured iterables like strings, where the
> whole is substantially more than the sum of its parts.
That's it: the unique property of strings is that composing & combining are the
same operation, while for true containers ther are distinct: when combining sets
(union), one gets a set at the same complexity level, whatever the items are,
while when composing sets one gets a set of sets.
> Actually, that would be another way of carving out the distinction -
> rather than trying to cover *all* Atomic types, just have an
> AtomicIterable ABC that indicated any structure where applying
> operations like "flatten" doesn't make sense. In addition to str,
> bytes and bytearray, memoryview and namedtuple instances would also be
> appropriate candidates.
Yes, maybe it's more practicle; but an ABC type common to strings (and the like)
and atomic types also makes sense.
Denis
PS: I had another common use case at times, with trees which leaves may be
string, or not (esp for their str and repr methods).
More information about the Python-ideas
mailing list