In a text file I have to write values, and next to each value either "NUMERIC"
if the value's type is int
or float
, or "NOMINAL"
, if the type is str
.
I know that this could be solved by an if
statement, but I would be pleased to use a more elegant way. I thought of multiplication with a boolean - something like that:
outputfile.write(value1 + "_NOMINAL" * (type(value1) is str)
+ "_NUMERIC" * (type(value1) is (float or int)))
This does not work - I don't know why... It works if I change the second expression into two conditions:
+ "_NUMERIC" * ((type(value1) is float) or (type(value1) is int))
Is there any other elegant, pythonic approach to get this done?