how convert x = ['30+20'] string to int

Viewed 43

Simple question from a simple guy..

How i convert x = ['30+20'] or x = ['1-500'] list string to int ?

Im trying to get out the operation of that list[string].

x = [50] or x = [-499]

1 Answers
x = ['30+20'] 
print(sum([int(i) for i in x[0].split('+')]))

this gives just int without list
if you need it inside of list just wrap it into list()

Related