python - How to add up scraped strings representing integers? -


how add floats scraped?

for post in posts:     numberofitems = numberofitems + 1     print(numberofitems)     value = float(re.sub(r"[^\d.]", "", post.text))     print("chaos orbs: %s" % value)     print(value) 

like this, print(value1 + value2 + value3) but, random amount not know, can't make variables

use sum():

for post in posts:     ... # rest of code snippet posted  print(sum(float(re.sub(r"[^\d.]", "", post.text)) post in posts)) 

outside of loop add values , print out sum.


alternatively, if want use existing loop somehow avoid iterating twice, how about:

summed_values = 0 post in post:     ... # rest of code snippet posted     summed_values += value 

Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -