[Python-3000] iter_flatten was: Making strings non-iterable

Baptiste Carvello baptiste13 at altern.org
Tue Apr 18 10:12:16 CEST 2006


Raymond Hettinger a écrit :
> [Brian Harring]
> 
>>The issue I'm seeing is that the wart you're pointing at is a
>> general issue not limited to strings- everyone sooner or later
>> has flattening code that hits the "recursively iterate over
>> this container, except  for instances of these classes".  
> 
> 
> Good recap.  For more info, search comp.lang.python for previous
> discussions about a proposed iter_flatten() function.  One of the
> conclusions was that a general algorithm would need to accept a user
> specified test for atomicity so it would know where to recurse and a
> where not to (the answer to that is application dependent).
> 
one useful test for that case could be:
 >>> item in item

This returns True for string-like objects, False for other sane (non infinite) 
iterables. Anyhow, when it returns True, you most definitely want to stop recursing!

Baptiste



More information about the Python-3000 mailing list