How do I replace characters in a string in Python?
<p>I'm trying to find the best way to do the following:</p>

<p>I have a string lets say:</p>

<pre><code>str = "pkm adp"
</code></pre>

<p>and I have a certain code in a dictionary to replace each charecter such as this one:</p>

<pre><code>code =  {'a': 'c', 'd': 'a', 'p': 'r', 'k': 'e', 'm': 'd'}
</code></pre>

<p>(<code>'a'</code> should be replaced by <code>'c'</code>, <code>'d'</code>  by <code>'a'</code> ...)</p>

<p>How can I convert the first string using the required characters from the dictionary to get the new string? Here for example I should get <code>"red car"</code> as the new string.</p>
