How can I append data to a list from a file when it has both a string and a number? I.e. if it's in the following form: circle,4.3. My code says the following but it doesn't seem to work: for line in inputfile: line.strip() y = line.split(',') ShapeList.append(y[0])(y[1])) Any ideas would be appreciated. Thanks!
Maybe you need to cast the float?
Not quite sure what you are trying to do... what's the expected result?
?? ShapeList.append((y[0],(y[1]))
I've tried it with float but no luck. I'm just trying to read the data from a file in the above form, then send it to another class to print it out. It's from PS10 problem 4, 2008 course. It should be quite straight forward but I'm having some problems with it. If anyone has done it I'd be grateful if I could see your solution. Thanks for your help anyways!
the append function of list takes exactly one argument, so you can do ... ShapeList.append(y[0]) ShapeList.append(y[1])
or rather a better way would be to make a list of lists, ShapeList.append ( [ y[0], y[1] ] )
Join our real-time social learning platform and learn together with your friends!