title: Python: Splitting numbers from text and then summing them
body: <p>All I have a text file formatted like below which I am bringing into Python:</p>
  
  <pre><code>    hammer#9.95
      saw#20.15
      shovel#35.40
  </code></pre>
  
  <p>Ultimately I want to develop a dynamic query that allows me to remove the '#' symbol and replace with a '$' symbol, and then add up the values within the text file/count the number of items within. I came up with this through some trial and error, but it isn't dynamic to handle changes in the text file:</p>
  
  <pre><code> # display header line for items list
  print('{0: &lt;10}'.format('Item'), '{0: &gt;17}'.format('Cost'), sep = '' )
  
  # add your remaining code below
  with open('invoice.txt','rt') as infile:
      for line in infile:
          print("{:&lt;21} {}".format(line.strip().split('#')[0],"$"+line.strip().split("#")[1]))
  
  print(' ')
  str1 = 'Total cost\t' +'      ' + '$65.50'
  print(str1)
  
  str2 = 'Number of tools\t' + '           ' +'3'
  print(str2)
  </code></pre>
  
  <p>Any suggestions? Thanks ahead of time for reading.</p>