Python script stuck in infinite loop
<p>I am writing a beginner python script for the python challenge ARG. The basic aim is to write a script that will read through a mass of text, pass through only the lower-case characters with exactly 3 capitals either side. The script is supposed to look at an incoming character from a list, store the next 3 characters and previous 3 characters in a list. Once this has happened, the script evaluates whether or not the incoming character is a capital, if it is the loop starts over, if not the script then evaluates if all three characters in the list are capitalised. If the conditions are met, the script should print the current character, else the loops starts over. </p>

<p>Whenever I run this script I am left with no debug/error/warnings about the code but it never completes or writes anything to the file. </p>

<p>here is the code I have written, any help would be appreciated. </p>

<pre><code>#code, where f = text to be processed, d = text file to be written to

f = open("test.txt", "r+")
f = f.read()
fList = list(f)
limit = len(fList)

#Set location of result
d = open("noided.txt", "r+")
i, j, k = [0, 0, 0]

#Main loop
#While there are characters left to be processed
while i &lt; limit:
    #Skip the first 4 characters
    if i &lt; 4:
        #print i, fList[i]
        i += 1
    else:
        #print i, fList[i]
        currentChar = fList[i]
        count = 0
        prevChars = [fList[i-1],fList[i-2],fList[i-3]]
        nextChars = fList[i:i + 3]

        if currentChar.isupper():

            i += 1

        else:
            while k &lt; 3:
                if prevChars[k].isupper() and nextChars[k].isupper():
                    count += 1
                    k += 1
                elif count == 3:
                    print currentChar
                    d.write(currentChar)
                    i += 1
                else:
                    i += 1
</code></pre>

<p>For starters, you have no variable named limit. Second, it would be easier to use stack type of list. Think of the stack as a stack of papers. You can parse the letters from the file into the stack (using a for loop), but then you can compare each character before it enters the stack, making this module useful for this kind of project</p>

python python-2.7