Python Challenge level 3. Why isn't my code working?
<p>So I know this is very dirty and probably inefficient code, but I was just trying to see if I could get it to work. I just don't understand why it's not working... The text from the file I'm accessing is in the source of <a href="http://www.pythonchallenge.com/pc/def/equality.html" rel="nofollow">http://www.pythonchallenge.com/pc/def/equality.html</a>. Any help?</p>

<pre><code>#! /usr/bin/python

# This program searches a string for a lowercase letter that has 3, and only 3,
# uppercase letters to the left of it, and 3, and only 3, uppercase letters to
# the right of it. It then returns that lowercase letter.

from string import lowercase
from string import uppercase

# Open the text file containing the string and set it to variable str
fileHandle = open ( 'bodyguards.txt', 'r' )
str = fileHandle.read()
fileHandle.close()
#str = 'BIGaBIGaBIGaBIG'

# Search for a lowercase letter.
def isitlower(str):
    for a in str :
        if a in lowercase:
            letterposition = str.index(a) 
            r =threebgright(letterposition)
            l =threebgleft(letterposition)
            if r !=None and l !=None:
                print l,":",a,":", r

def threebgright(letterposition):
    if str[letterposition + 1] in uppercase and str[letterposition +2] in uppercase and         str[letterposition + 3] in uppercase and str[letterposition + 4] not in uppercase:
        return str[letterposition+1], str[letterposition+2], str[letterposition+3]
    else:
        return None

def threebgleft(letterposition):
    if str[letterposition - 1] in uppercase and str[letterposition -2] in uppercase and     str[letterposition - 3] in uppercase and str[letterposition - 4] not in uppercase:
        return str[letterposition-1], str[letterposition-2], str[letterposition-3]
    else:
        return None

isitlower(str)
</code></pre>
