So you want integers and floats that are equal to integers?
def is_whole(d):
"""Whether or not d is a whole number."""
return isinstance(d, int) or (isinstance(d, float) and d.is_integer())
In use:
>>> for test in (1, 1.0, 1.1, "1"):
print(repr(test), is_whole(test))
1 True # integer
1.0 True # float equal to integer
1.1 False # float not equal to integer
'1' False # neither integer nor float
You can then apply this to your list with all
and map
:
if all(map(is_whole, List)):
or a generator expression:
if all(is_whole(d) for d in List):