Thursday, January 25, 2018

python - How to convert integers in a list to int()?

I'm making a function that evaluates maths in a string. First, it takes the string and then converts it to a list.



I tried converting the entire array into an array of integers, but I run into an error when the array looks like this: ["hello",1,"*",2] as everything isn't a number.



I want to only convert the integers in the array ["1","2","hello","3"] to integers, so the array becomes [1,2,"hello",3]



That way, I can do maths on the integers and not have them treated as strings, as currently, when I do this:



1 + 2



I get 12 as the output.
I want 3 as the output.

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...