On Sun, Oct 03, 2021 at 01:26:06AM -0000, Debashish Palit wrote:

> The floatify solution is a bit involved - using map inside a list 
> comprehension. Usually list comprehensions replace the usage of map. 
> Also floatify requires 5 extra lines of code (putting `return` on the 
> same line is not a best practice). Why not do it with one simple line 
> of code ?

Of course you can do it with one line of code. Nobody is telling you 
that you mustn't use your "isfloat()" function in your own code. Go 
right ahead.

We're just pointing out why it is not likely to be made into a built in 
string method.

- too narrow use: the good use cases for it are very small;

- too specialized: it doesn't generalise to other numeric formats 
without re-writing the function;

- awkward interface: it returns a three-way flag, True, False or None;

- wrongly named: isfloat() doesn't return a True/False bool to tell you 
whether the string is a float, it returns three values to tell you 
whether it is a float, an int or neither;

- duplicated effort: having called the method, you still have to call 
float() or int() again to actually get the result you actually want.


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

Reply via email to