Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 19 Online
OpenStudy (anonymous):

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!

OpenStudy (anonymous):

Maybe you need to cast the float?

OpenStudy (anonymous):

Not quite sure what you are trying to do... what's the expected result?

OpenStudy (anonymous):

?? ShapeList.append((y[0],(y[1]))

OpenStudy (anonymous):

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!

OpenStudy (shubha):

the append function of list takes exactly one argument, so you can do ... ShapeList.append(y[0]) ShapeList.append(y[1])

OpenStudy (shubha):

or rather a better way would be to make a list of lists, ShapeList.append ( [ y[0], y[1] ] )

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Latest Questions
Mari103: How to pop out like a Jacc In the box
33 minutes ago 0 Replies 0 Medals
Breathless: Spooky witch but cute
7 hours ago 3 Replies 0 Medals
Arriyanalol: help
7 hours ago 10 Replies 2 Medals
Arriyanalol: @tinydinoUwU stop trying to find a argument u blad lil boy
1 day ago 5 Replies 4 Medals
Jaded012023: Please tell me what you all think of this song
10 hours ago 6 Replies 1 Medal
Arriyanalol: bro how
10 hours ago 2 Replies 3 Medals
Arriyanalol: cant wait for the new bluey movie in 2027
1 day ago 12 Replies 2 Medals
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!