I have a list of values, that can be string like "string" and can be numbers that are given in a string format as "2.3"
I want to convert strings of certain value to a number ("N/A"->-1) and to leave any other string untouched, moreover I need to convert the numbers that are given in a string, in the float format to string format ("1.0"->1) etc.
I managed to do so if I first run all over the list and convert the N/A values to -1 like so
for i in list:
if i=="N/A":
i=-1
and then run with
l = [int(i) for i in l]
But I still might have strings, other then "N/A" and I don't want to have trouble trying to convert them, and need to use try in the second loop. how can I do that?
This is the code i try but i gives me syntax error
l = [try: int(float(i)) except: pass] for i in l
Origin list example: ["1.0","N/A","lol"] i need it to be [1,-1,"lol"]