Ask coding questions

← Back to all posts
combining integers in list?
DavidSafro (19)

Ok so I have this scenario, Whenever I run quadratic function in this code, I have the user enter a string a.k.a the equation to be solved, and then I split the "string" into separate characters in a list. I was going to be fine with that until I ran into a dilemma: what if a coefficient was a two digit number? ex) 10x^2+34x+75. how could I combine the 1 and 0 for example to create 10 as a list component instead of 1 and 0 being separated?

Answered by SixBeeps (5052) [earned 5 cycles]
View Answer
Comments
hotnewtop
SixBeeps (5052)

If you still want to split the coefficients with commas, you can use split() to make it into an array:

new_list = csv.split(',')

This splits a comma separated string into a list by splitting it at every comma.

SixBeeps (5052)

@DavidSafro split() is a function built into strings, so for example in your quadratic code, you store a CSV into the equation variable. To split this string into list_eq, you'd do

list_eq = equation.split(",")

At least that's what it sounds like you're trying to do.