How can i remove all extra characters from list of strings to convert to ints
<p>Hi I'm pretty new to programming and Python, and this is my first post, so I apologize for any poor form.</p>

<p>I am scraping a website's download counts and am receiving the following error when attempting to convert the list of string numbers to integers to get the sum.
<strong>ValueError: invalid literal for int() with base 10: '1,015'</strong></p>

<p>I have tried .replace() but it does not seem to be doing anything.</p>

<p>And tried to build an if statement to take the commas out of any string that contains them:
<a href="http://stackoverflow.com/questions/3437059/does-python-have-a-string-contains-substring-method">Does Python have a string contains substring method?</a></p>

<p>Here's my code:</p>

<pre><code>    downloadCount = pageHTML.xpath('//li[@class="download"]/text()')
    downloadCount_clean = []

    for download in downloadCount:
        downloadCount_clean.append(str.strip(download))

    for item in downloadCount_clean:
        if "," in item:
            item.replace(",", "")
    print(downloadCount_clean)

    downloadCount_clean = map(int, downloadCount_clean)
    total = sum(downloadCount_clean)
</code></pre>

<p>Strings are not mutable in Python. So when you call <code>item.replace(",", "")</code>, the method returns what you want, but it is not stored anywhere (thus not in <code>item</code>).</p>

<p><strong>EDIT :</strong></p>

<p>I suggest this :</p>

<pre><code>for i in range(len(downloadCount_clean)):
    if "," in downloadCount_clean[i]:
        downloadCount_clean[i] = downloadCount_clean[i].replace(",", "")
</code></pre>

<p><strong>SECOND EDIT :</strong></p>

<p>For a bit more simplicity and/or elegance :</p>

<pre><code>for index,value in enumerate(downloadCount_clean):
    downloadCount_clean[index] = int(value.replace(",", ""))
</code></pre>

python replace string-conversion