python - Single quotes around list elements that should be floats -


i asked "return list of tuples containing subset name (as string) , list of floating point data values".

my code is:

def load_data(filename):      fileopen = open(filename)     result_open=[]     line in fileopen:         answer = (line.strip().split(","))         result_open.append((answer[0],(answer[1:])))     return result_open 

however, when run code, following appears:

[('slow loris', [' 21.72', ' 29.3', ' 20.08', ' 29.98', ' 29.85', ' 26.22', ' 19......)] 

is there anyway change tuple appear without apostrophes? want like:

[('slow loris', [21.72, 29.3, 20.08, 29.98, 29.85, 6.22, 19......)] 

line string, , line.strip().split(",") list of strings. need convert string values float or decimal values. 1 way be:

result_open.append((answer[0], [float(val) val in answer[1:]])) 

that raise exception on values can't converted float, should think how want handle such input.


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -