So I have a list of string a = ['1', '2', ''] or a = ['1', '2', 'NAN'], and I want to convert it to [1, 2, 0] or [1, 2, -1] (namely NAN to -1); I used
a = [int(ele) for ele in a], but got an error
ValueError: invalid literal for int() with base 10: ''
So the empty string cannot be converted automatically. Of course I could explicitly loop through the list ,but I wonder if there are more elegant/compact/efficient way.