Why is my generator implementation incorrect in Python?
<p>So basically i am writing a program where i need to take in a file that contains uppercase letters, that may or may not be seperated by white space or new lines, and return a generator over the letters in the file.</p>

<p>For example: </p>

<pre><code>Z FM
TM  CC
</code></pre>

<p>Would return a generator with an output of "Z","F","M","T","M","C","C"</p>

<p>The function should be a generator, so it will only load in letters at a time instead of the entire file.</p>

<p>Anyways, here is what i have so far. ANyone tell me where i went wrong?</p>

<pre><code>def buildGen:
    with open(filename) as sample:
        for word in sample:
           for ch in word:
               yield ch
</code></pre>

<p>Assume only <code>uppercase letters</code> will be included in the output and <code>only load in letters at a time instead of the entire file</code>:</p>

<pre><code>def buildGen():
    with open(filename) as sample:
        while True:
            ch = sample.read(1)
            if ch:
                if 'A' &lt;= ch &lt;= 'Z':
                    yield ch
            else:
                break
</code></pre>

python generator