A more pythonic way of doing the following?
<p>A more pythonic way of doing the following? In this example, I'm trying to build comments (a dict) to be key-value pairs where the key is the unmodified-version, and the value is the return value from a function where the key was passed as an arg.</p>

<pre><code>def func(word):
    return word[-1:-6:-1].upper()

subs = {
    'ALLOWED': ['one', 'two'],
    'DISALLOWED': ['three', 'four']
}

comments = {}
for sub in subs['ALLOWED']:
    # reverse and uppercase
    comments[sub] = func(sub)

print(comments)
</code></pre>

<p>Anyone have recommendation? It's not exactly important to have this done, but I love learning python idioms and ways to make my code more pythonic. Thanks!</p>

<p>Use a <a href="https://www.python.org/dev/peps/pep-0274/" rel="nofollow">dict comprehension</a> instead of building your dictionary in a <code>for</code> loop:</p>

<pre><code>comments = {key: func(key) for key in subs['ALLOWED']}
</code></pre>

python python-3.x