Output dictionary data dynamically from a python for loop
<p>here, I am trying to spell check a txt file. first half of my code outputs original (var word) and corrected, if any, (var spell(word)). my replacement code uses a data structure like <code>{'zero':'0', 'temp':'bob', 'garbage':'nothing', 'garnvsh': 'garnish'}</code>. Now I would like to produce the same data structure from the loop dynamically. Can you, please, help me figure it out how to output similar data structure with <code>var word</code> and <code>var spell(word)</code> with first half of the code?</p>

<pre><code>import os, os.path
from textblob import TextBlob
from autocorrect import spell
import fileinput
import json

data = []

with open("input.txt", "r") as my_file:
    for line in my_file.readlines():
        zen = TextBlob(line)
        for word in zen.words:
            word, spell(word)

replacements = {'zero':'0', 'temp':'bob', 'garbage':'nothing', 'garnvsh': 'garnish'}

with open('../input.txt') as infile, open('../output.txt', 'w') as outfile:
    for line in infile:
        for src, target in replacements.iteritems():
            line = line.replace(src, target)
        outfile.write(line)
</code></pre>

<p>I suppose you want to <a href="http://stackoverflow.com/a/14507637/1040597">create dictionary</a> which its keys are <code>word</code> and values are <code>spell(word)</code>.</p>

<pre><code>my_dict = { word: spell(word) for word in zen.words }
</code></pre>

python