On Wed, Apr 14, 2021 at 09:05:17AM -0700, Christopher Barker wrote:
so that one could write: for i in 23: ...
I am proposing this ill run the cycle ones with i=23.
iter(5) Should return the same thing as: iter((5,))
Yes. As I wrote in the "traverse" example below iter(s) should return the same thing as: from collections.abc import Iterable iter(s if isinstance(s, Iterable) else (s,))
which is really odd. It makes some small amount of sense if you assume that all sequences are "flat". But even then, the distinction between a single item and a sequence with one item in it a critical distinction that should not be masked.
Why, please? Can you give more (concrete) examples, please?
Also - if you do this for integers, do you do it for all numbers? what about any other single object?
As I wrote for any (not iterable) scalar/single value/object.
(and THAT would get really strange with strings!)
Strings are lists by definition. Yes, the behaviour for strings would be surprising. But why to discriminate all other types, because strings are lists?
Error? Perhaps feature! You will get the desired behaviour and don't need to handle corner case like this.
from collections.abc import Iterable def traverse(s): for x in s if isinstance(s, Iterable) else (s,): print(f"{x=}")
traverse(5) traverse(range(3))
H.