On Sun, Oct 3, 2021 at 1:55 AM Debashish Palit <[email protected]> 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 -- [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/MU4VSONSNIJUU645CFGOU7Z43MJM57VA/
Code of Conduct: http://python.org/psf/codeofconduct/