
On Fri, Apr 30, 2021 at 9:06 AM David Álvarez Lombardi < alvarezdqal@gmail.com> wrote:
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 (in the general case) seems to be the following.
clean = "".join(char for char in dirty if char in string.ascii_letters)
If a feature like this is useful -- and I'm not sure it is -- there is a much better way to do this IMHO. Add a new format converter to the syntax for replacement fields: *>>> f"{c for c in dirty if c in string.ascii_letters !j}"* *'fsjGe'* where *!j* means join. It could optionally take a separator string as in this example: *>>> f"{chr(65 + i) for i in range(4) !j('-')}"* *'A-B-C-D'* --- Bruce