Python - use lists instead of strings?
<p><a href="http://stackoverflow.com/questions/1228299/change-one-character-in-a-string-in-python">From an S.O answer</a>:</p>

<p>"Don't modify strings.</p>

<p>Work with them as lists; turn them into strings only when needed.</p>

<p>... code sample ...</p>

<p>Python strings are immutable (i.e. they can't be modified). There are a lot of reasons for this. Use lists until you have no choice, only then turn them into strings."</p>

<p>Is this considered best practice? </p>

<p>I find it a bit odd that Python has methods that return new modified strings (such as upper(), title(), replace() etc.) but doesn't have an insert method that returns a new string. Have I missed such a method?</p>

<p>Edit: I'm trying to rename files by inserting a character:</p>

<pre><code>import os
for i in os.listdir('.'):
    i.insert(3, '_')
</code></pre>

<p>Which doesn't work due to immutability. Adding to the beginning of a string works fine though:</p>

<pre><code>for i in os.listdir('.'):
    os.rename(i, 'some_random_string' + i)
</code></pre>

<p>Edit2: the solution:</p>

<pre><code>&gt;&gt;&gt; for i in os.listdir('.'):                                                │··
...  os.rename(i, i[:4] + '_' + i[4:])
</code></pre>

<p>Slicing certainly is nice and solves my problem, but is there a logical explanation why there is no insert() method that returns a new string? </p>

<p>Thanks for the help.</p>
