
On 30/04/2021 19:14, David Álvarez Lombardi wrote:
I appreciate the feedback, but I don't think the proposed ideas address any of my points.
1. *Consistency *(with other comprehensions)
You're actually adding an inconsistency: having a comprehension inside string quotes instead of not.
1. *Intuitiveness *(as opposed to str.join(iter)which is widely deemed to be confusing and seemingly-backwards)
Yes I agree your examples read nicely, without the usual boilerplate. Whether this is worth adding to the language is a moot point. Every addition increases the size of the compiler/interpreter, increases the maintenance burden, and adds to the learning curve for newbies (and not-so-newbies). As far as I can see in every case c'SOMETHING' can be replaced by ''.join(SOMETHING) or str.join('', (SOMETHING)) Having many ways to do the same thing is not a plus.
1. *Efficiency *(with respect to line count and function calls... though perhaps the cpython implementation could actually avoid the type switching and improve time complexity)
It seems to me it would probably save a function call. That seems like a minor consideration.
1. *Readability *(due to /much /clearer typing and lack of highly-nested function calls ( f"[{','.join('0123')}]" ) and higher-order functions ( genjoin('', '', '')('0123') )
This seems to me to be making the same point as "Intuitiveness". Best wishes Rob Cliffe (I can't hack your heading auto-numbering so they've all ended up being numbered 1.)
I would also like readers/commenters to consider the fact that, though I have only provided one use-case, the proposed enhancement would serve as the primary syntax for constructing or filtering a string *when dependent on any other iterable or condition*. I believe this to be an extremely common (almost universal) use-case. Here are just a couple more examples.
new = c"x.lower() for x in old if x in HARDCODED_LIST" # filter-in chars that appear in earlier-defined HARDCODED_LIST and convert to lower new = c"x for x in old if not x.isprintable()" # filter-in non-printable chars new = c"str(int(x) + 1) for x in old if isinstance(x, int)" # increment all integers by 1
To me, it is hard to see how any argument against this design (for anything other than implementation-difficulty or something along these lines) can be anything but an argument against iter comprehensions in general... but if someone disagrees, please say so.
My goal is to /decrease/ complexity, and personal/higher-order/nested procedures do not accomplish this in my eyes.
Thank you.
DQAL
On Fri, Apr 30, 2021 at 1:10 PM Jonathan Fine <jfine2358@gmail.com <mailto:jfine2358@gmail.com>> wrote:
On Fri, Apr 30, 2021 at 6:00 PM Chris Angelico <rosuav@gmail.com <mailto:rosuav@gmail.com>> wrote:
For those cases where you're merging literal parts and generated parts, it may be of value to use an f-string:
>>> f"[{','.join('0123')}]" '[0,1,2,3]'
The part in the braces is evaluated as Python code, and the rest is simple literals.
For readability, reuse and testing I think it often helps to have a function (whose name is meaningful). We can get this via as_list_int_literal = gensep(',', '[', ']')
It would also be nice to allow as_list_int_literal to have a docstring (which could also be used for testing).
I accept that in some cases Chris's ingenious construction has benefits.
-- Jonathan _______________________________________________ Python-ideas mailing list -- python-ideas@python.org <mailto:python-ideas@python.org> To unsubscribe send an email to python-ideas-leave@python.org <mailto:python-ideas-leave@python.org> https://mail.python.org/mailman3/lists/python-ideas.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/UVTLPO... <https://mail.python.org/archives/list/python-ideas@python.org/message/UVTLPO...> Code of Conduct: http://python.org/psf/codeofconduct/ <http://python.org/psf/codeofconduct/>
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@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/QXDXJ3... Code of Conduct: http://python.org/psf/codeofconduct/