Returning a dict value for a key, or the key if the dict does not contain that key
<p><strong>Background</strong>: It had been a while since I had read <a href="http://stackoverflow.com/questions/228181/the-zen-of-python">The Zen of Python</a> so I went to the interpreter and typed <code>import this</code>, then out of curiosity I inspected the contents of the newly imported <code>this</code> module and saw that <code>this</code> has some interesting attributes, most notably:</p>

<pre><code>&gt;&gt;&gt; this.s
"Gur Mra bs Clguba, ol Gvz Crgref\n\nOrnhgvshy vf orggre guna htyl.\nRkcyvpvg vf orggre guna vzcyvpvg.\nFvzcyr vf orggre guna pbzcyrk.\nPbzcyrk vf orggre guna pbzcyvpngrq.\nSyng vf orggre guna arfgrq.\nFcnefr vf orggre guna qrafr.\nErnqnovyvgl pbhagf.\nFcrpvny pnfrf nera'g fcrpvny rabhtu gb oernx gur ehyrf.\nNygubhtu cenpgvpnyvgl orngf chevgl.\nReebef fubhyq arire cnff fvyragyl.\nHayrff rkcyvpvgyl fvyraprq.\nVa gur snpr bs nzovthvgl, ershfr gur grzcgngvba gb thrff.\nGurer fubhyq or bar-- naq cersrenoyl bayl bar --boivbhf jnl gb qb vg.\nNygubhtu gung jnl znl abg or boivbhf ng svefg hayrff lbh'er Qhgpu.\nAbj vf orggre guna arire.\nNygubhtu arire vf bsgra orggre guna *evtug* abj.\nVs gur vzcyrzragngvba vf uneq gb rkcynva, vg'f n onq vqrn.\nVs gur vzcyrzragngvba vf rnfl gb rkcynva, vg znl or n tbbq vqrn.\nAnzrfcnprf ner bar ubaxvat terng vqrn -- yrg'f qb zber bs gubfr!"
&gt;&gt;&gt; this.d
{'A': 'N', 'C': 'P', 'B': 'O', 'E': 'R', 'D': 'Q', 'G': 'T', 'F': 'S', 'I': 'V', 'H': 'U', 'K': 'X', 'J': 'W', 'M': 'Z', 'L': 'Y', 'O': 'B', 'N': 'A', 'Q': 'D', 'P': 'C', 'S': 'F', 'R': 'E', 'U': 'H', 'T': 'G', 'W': 'J', 'V': 'I', 'Y': 'L', 'X': 'K', 'Z': 'M', 'a': 'n', 'c': 'p', 'b': 'o', 'e': 'r', 'd': 'q', 'g': 't', 'f': 's', 'i': 'v', 'h': 'u', 'k': 'x', 'j': 'w', 'm': 'z', 'l': 'y', 'o': 'b', 'n': 'a', 'q': 'd', 'p': 'c', 's': 'f', 'r': 'e', 'u': 'h', 't': 'g', 'w': 'j', 'v': 'i', 'y': 'l', 'x': 'k', 'z': 'm'}
</code></pre>

<p>I figured the Zen could be obtained from <code>this.s</code> by using the character mapping in <code>this.d</code>, so I came up with the following line that does in fact print the Zen of Python:</p>

<pre><code>"".join(this.d[c] if c in this.d else c for c in this.s)
</code></pre>

<p>I then went back to Stack Overflow wiki linked above thinking that I would post this interesting information, but of course it was already there, and had been for 2 and a half years.  However, that post uses the following method to obtain the Zen:</p>

<pre><code>"".join(c in this.d and this.d[c] or c for c in this.s)
</code></pre>

<p>This saves a few characters, but it is slightly less obvious what is going on (in my opinion).  So I figured I would check out which method <code>this.py</code> uses, of course it is a more elegant solution than either of the above:</p>

<pre><code>"".join(this.d.get(c, c) for c in this.s)
</code></pre>

<p><strong>Question</strong>: This process got me thinking, are there any performance differences between these three methods that make any of them clearly better?</p>

<p>Obviously the last one is great because it is way more readable, but I have heard there is some overhead associated with Python function calls so it wouldn't surprise me to learn that one of the other methods was faster.</p>

<p>So, if any of these methods are more efficient than the others, which is it and why?</p>
