I appreciate the feedback, but I don't think the proposed ideas address any
of my points.
1. *Consistency *(with other comprehensions)
2. *Intuitiveness *(as opposed to str.join(iter) which is widely deemed
to be confusing and seemingly-backwards)
3. *Efficiency *(with respect to line count and function calls... though
perhaps the cpython implementation could actually avoid the type switching
and improve time complexity)
4. *Readability *(due to *much *clearer typing and lack of
highly-nested function calls ( f"[{','.join('0123')}]" ) and
higher-order functions ( genjoin('', '', '')('0123') )
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 <[email protected]> wrote:
> On Fri, Apr 30, 2021 at 6:00 PM Chris Angelico <[email protected]> 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 -- [email protected]
> To unsubscribe send an email to [email protected]
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/[email protected]/message/UVTLPOK4S663GIMSTUWBDMFSFHUEYHGJ/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/QXDXJ3G6MU4OZTHYOD25EKRIFKHOTZQZ/
Code of Conduct: http://python.org/psf/codeofconduct/