[Python-ideas] Re: String comprehension

2021-04-30 Thread Valentin Berlier
> The builtin interables bytearray, bytes, enumerate, filter frozenset, map, > memoryview, range, reversed, tuple and zip suggest differently. enumerate, filter, map, range, reversed and zip don't apply because they're not collections, you wouldn't be able to store the result of the computation

[Python-ideas] Re: String comprehension

2021-04-30 Thread Valentin Berlier
> c"f(c) for c in some_string if g(c)" Even this example would allow the interpreter to skip building the generator object and having to feed the result of every f(c) back into the iterator protocol. This is similar to f-strings vs str.format. You could say that f-strings are redundant because

[Python-ideas] Adding str.remove()

2021-04-30 Thread David Mertz
I was actually thinking about this before the recent "string comprehension" thread. I wasn't really going to post the idea, but it's similar enough that I am nudged to. Moreover, since PEP 616 added str.removeprefix() and str.removesuffix(), this feels like a natural extension of that. I find my

[Python-ideas] Re: String comprehension

2021-04-30 Thread Steven D'Aprano
I thought I had sent a response to this a few hours ago, but it seems to have been eaten by the email gremlins. Apologies if this ends up as a duplicate. On Fri, Apr 30, 2021 at 12:03:15PM -0400, David Álvarez Lombardi wrote: > I propose a syntax for constructing/filtering strings analogous to t

[Python-ideas] Re: String comprehension

2021-04-30 Thread Steven D'Aprano
On Sat, May 01, 2021 at 03:05:51AM -, Valentin Berlier wrote: > It's kind of weird that people seem to be missing the point about > this. Python already has comprehensions for all the iterable builtins > except strings. No it doesn't. I count 15 builtin iterables, only three have comprehen

[Python-ideas] Re: String comprehension

2021-04-30 Thread Chris Angelico
On Sat, May 1, 2021 at 1:43 PM Valentin Berlier wrote: > > > the ONLY predicate that can be expressed about a single character is it > > being a member of a subset of all Unicode characters > > You seem to be assuming that the comprehension would be purposefully > restricted to iterating over st

[Python-ideas] Re: String comprehension

2021-04-30 Thread 2QdxY4RzWzUUiLuE
On 2021-05-01 at 03:05:51 -, Valentin Berlier wrote: > Also I haven't seen anyone acknowledge the potential performance > benefits of string comprehensions. The "".join() idiom needs to go > through the entire generator machinery to assemble the final string, > whereas a decent implementation

[Python-ideas] Re: String comprehension

2021-04-30 Thread David Mertz
Ok... If the suggestion is trying concatenation of arbitrary objects that aren't strings, I go from thinking it's unnecessary to thinking it's a massively horrible idea. On Fri, Apr 30, 2021, 11:43 PM Valentin Berlier wrote: > > the ONLY predicate that can be expressed about a single character i

[Python-ideas] Re: String comprehension

2021-04-30 Thread Valentin Berlier
> the ONLY predicate that can be expressed about a single character is it being > a member of a subset of all Unicode characters You seem to be assuming that the comprehension would be purposefully restricted to iterating over strings. The original author already provided examples with predicat

[Python-ideas] Re: String comprehension

2021-04-30 Thread David Mertz
Strings are VERY different from other iterables. Every item in a string is itself an (iterables) string. In many ways, strings are more like scalars, and very often we treat them as such. You could make an argument that e.g. a NumPy array of homogenous scalars is similar. However, that would be a

[Python-ideas] Re: String comprehension

2021-04-30 Thread Valentin Berlier
It's kind of weird that people seem to be missing the point about this. Python already has comprehensions for all the iterable builtins except strings. The proposed syntax doesn't introduce any new concept and would simply make strings more consistent with the rest of the builtins. The argument

[Python-ideas] Re: String comprehension

2021-04-30 Thread David Mertz
Given that there is very little you can test about a single character, a new construct feels excessive. Basically, the only possible question is "is it in this subset of codepoints?" However, that use is perfectly covered by the str.translate() method already. Regular expressions also cover this w

[Python-ideas] Re: String comprehension

2021-04-30 Thread Chris Angelico
On Sat, May 1, 2021 at 6:23 AM Rob Cliffe via Python-ideas wrote: > 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

[Python-ideas] Re: String comprehension

2021-04-30 Thread Rob Cliffe via Python-ideas
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.

[Python-ideas] TACE16 text encoding for Tamil language

2021-04-30 Thread பா . மு . செல்வக்குமார்
Hi, I want to use this encoding [1] for Tamil language text because it is more consistent with the language's nature, and Unicode encoding severely damages(read more here[2]

[Python-ideas] Re: String comprehension

2021-04-30 Thread 2QdxY4RzWzUUiLuE
On 2021-04-30 at 14:14:50 -0400, David Álvarez Lombardi wrote: [...] > 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 char

[Python-ideas] Re: String comprehension

2021-04-30 Thread David Álvarez Lombardi
Small correction: isinstance(x, int) should be x.isdigit() in the last example. On Fri, Apr 30, 2021 at 2:14 PM David Álvarez Lombardi < alvarezd...@gmail.com> wrote: > I appreciate the feedback, but I don't think the proposed ideas address > any of my points. > >1. *Consistency *(with other

[Python-ideas] Re: String comprehension

2021-04-30 Thread David Álvarez Lombardi
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

[Python-ideas] Re: String comprehension

2021-04-30 Thread Jonathan Fine
On Fri, Apr 30, 2021 at 6:00 PM Chris Angelico 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 lit

[Python-ideas] Re: String comprehension

2021-04-30 Thread Chris Angelico
On Sat, May 1, 2021 at 2:52 AM Jonathan Fine wrote: > > Hi David > > I see where you are coming from. I find it helps to think of sep.join as a > special case. Here's a more general join, with sep.join equivalent to > genjoin(sep, '', ''). > > def genjoin(sep, left, right): > def fn(

[Python-ideas] Re: String comprehension

2021-04-30 Thread Jonathan Fine
Hi David I see where you are coming from. I find it helps to think of sep.join as a special case. Here's a more general join, with sep.join equivalent to genjoin(sep, '', ''). def genjoin(sep, left, right): def fn(items): return left + sep.join(items) + right retur

[Python-ideas] String comprehension

2021-04-30 Thread David Álvarez Lombardi
I propose a syntax for constructing/filtering strings analogous to the one available for all other builtin iterables. It could look something like this. >>> dirty = "f8sjGe7" >>> clean = c"char for char in dirty if char in string.ascii_letters" >>> clean 'fsjGe' Currently, the best way to do this

[Python-ideas] Re: Changing The Theme of Python Docs Site

2021-04-30 Thread Rob Cliffe via Python-ideas
On 30/04/2021 07:06, Abdur-Rahmaan Janhangeer wrote: The Masonite docs for example is quite nice: https://docs.masoniteproject.com/ I read as far as the 4th sentence:     "Use it for your next SaaS!" [no link atached] What on earth (I wanted to use a st

[Python-ideas] Re: Changing The Theme of Python Docs Site

2021-04-30 Thread Abdur-Rahmaan Janhangeer
Greetings, That was an upto the point, precise and deep answer. Seems a design agency (who are Python programmers themselves, else they miss a thing or two) might do a nice job. Maybe what's missing is a design code (set of rules for headers, links, buttons etc) Well i subscribed to d...@python.o

[Python-ideas] Re: Changing The Theme of Python Docs Site

2021-04-30 Thread M.-A. Lemburg
Hi Abdur-Rahmaan, while I don't think our docs look particularly bad, freshening up the looks a bit every now and then certainly is something which should be considered to better show case the quality of the product "Python". In particular, it would make sense to bring the themes of the main www.