As mentioned, the all
function will do what you want. What you describe you're trying to do can also be done with the str.isnumeric()
function.
def foo(listOfInputs):
return all(map(str.isnumeric,listOfInputs))
Edit: I'm finding that it fails on ['1','2','3.14','4']
which is a little annoying. Maybe someone can come up with a cleverer solution than this, but I decided to wrap a slightly modified approach in a try
:
def foo(listOfInputs):
try:
return all(map(float,listOfInputs))
except ValueError:
return False
That works on:
['1','2','-3','4']
['1','2','3.14','4']