On Sun, Oct 3, 2021 at 1:55 AM Debashish Palit <dpali...@outlook.com> wrote:
>
> Ok it is a 3 way flag, but the code is not awkward. 'c' is just a name I 
> chose - it does not mean anything.
>
> The check for a valid number can be used on a list of strings -
>
> [float(s) for s in lst if s.isfloat() is not None]
>
> No 3 way flag here. Difficult to do with EAFP.

If you want to filter a list to just those which don't raise
exceptions when you floatify them, just do that:

def floatify(n):
    try: return float(n)
    except ValueError: return None

[n for n in map(floatify, lst) if n is not None]

Not everything has to be a built-in. The more specific it is to your
purposes, the better to just write your own function.

ChrisA
_______________________________________________
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/MU4VSONSNIJUU645CFGOU7Z43MJM57VA/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to