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.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/CJPRESBD7WYK6JD5DWYP4HGDWPG3KFLK/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to