How to cut from a string to a certain part?

Hello, is there a list of such strings.
a = ['Pizza "Pepperoni pizza" (thin crust)Size for selection: 25 cm 330 g + 0 RUB Ingredients:Bacon 50 g + 100 RUB Onion 20 g + 30 RUB', 'Pizza Pepperoni (thin crust)Size for choice: 30cm 330 g + 0.', 'Pizza "Royal" (thin crust)Size for selection: 25 cm 330 g + 0 RUB Ingredients:Bacon 50 g + 100 RUB Onion 20 g + 30 RUB.']


I have a large number of such strings in the list, I cut it grams+the sum of these rows that would have left only the name and size in cm.
March 19th 20 at 09:15
1 answer
March 19th 20 at 09:17
Solution
Here's mine not the best solution:
stroki = []
total = 0

info = ['Pizza "Pepperoni pizza" (thin crust)Size for selection: 25 cm 330 g + 0 RUB Ingredients:Bacon 50 g + 100 RUB Onion 20 g + 30 RUB',
 'Pizza Pepperoni (thin crust)Size for choice: 30cm 330 g + 0.',
 'Pizza "Royal" (thin crust)Size for selection: 25 cm 330 g + 0 RUB Ingredients:Bacon 50 g + 100 RUB Onion 20 g + 30 RUB.']

for count1 in range(0, len(info)): #promejutok in order to be able to element with conerete index
 predlozhenie = info[count1] #get every big line

 for count2 in range(0, len(predlozhenie)): #run the same way on the line
 gramm = predlozhenie[count2] #get each character

 if gramm == 'g': # if "g"
 stroka = predlozhenie[count2-4 : count2-1] # get slice, which will probably number(count2 can be subtracted from the number, and more
 stroki.append(stroka) # add to the array (you can do without it, but so understandable)

for count3 in stroki: #run these lines
 try: #since not all rows in this array can be converted to a number
 chislo = int(count3) #convert

 total = total + chislo #adder

except:
pass

print("Total: ", total)

Find more questions by tags Python