I'm trying to replace some placeholder text within a file with the contents of a list I've built. I step through the list, counting as I go, and do a search which changes depending on the count. The count is an integer that is a part of the search term I use in every loop.

I cannot for the life of me work out what's going on. I've printed everything I can think of and it looks like the search term matches. I've tried multiple methods of replace, but have stuck with the simple replace example to show. 

Sample text from the file, get's loaded into variable 'filedata':

`<core:para>ANSWER_1</core:para><core:para>2. Bilateral investment treaties</core:para><core:para>ANSWER_2</core:para><core:para>3. Domestic arbitration law</core:para><p>ANSWER_3</p><core:para>4. Domestic arbitration and UNCITRAL</core:para><core:para>ANSWER_4</core:para><core:para>5. Mandatory provisions</core:para><core:para>ANSWER_5</core:para><core:para>6. Substantive law</core:para><core:para>ANSWER_6</core:para><core:para>7. Arbitral institutions</core:para><core:para>ANSWER_7</core:para><core:para>8. Arbitrability</core:para><core:para>ANSWER_8</core:para><core:para>9. Requirements</core:para><core:para>ANSWER_9</core:para><core:para>10. Enforceability</core:para><core:para>ANSWER_10</core:para>`

Code:

```
x = 1            
answerlist = ['Oranges', 'Apples', 'Mangos', 'Cherries']

for a in answerlist:
    searchterm = '<core:para>ANSWER_' + str(x) +'</core:para>'
    newdata = filedata.replace(searchterm, a)
    x=x+1

```

For the purpose of the example I've hardcoded the answerlist variable above, but this is dynamically created in a larger loop. 

The expected result is:

`<core:para>Oranges</core:para><core:para>2. Bilateral investment treaties</core:para><core:para>Apples</core:para>`
etc

The actual result is:

`<core:para>ANSWER_1</core:para><core:para>2. Bilateral investment treaties</core:para><core:para>ANSWER_2</core:para>`

I've tested the pattern either side of x and that works fine, so the problem appears to be the x, somehow not converting into the string I think it is. 

Any ideas what the problem might be?