why this loop is running only once 2.0 remake

Viewed 53

Why is this first loop running only once?

I only know that this line is what causes this:

unchecked = text.pop(0)

how to fix it?

def search(text):
    text=list(text)
    pat=[]
    history=[]
    for char in text:
        print(char)
        negative=[]
        pat.append(char)
        for i in range(int(len(text)/len(pat))):
            for char in pat:
                unchecked = text.pop(0)
                if unchecked == char:
                    history.append(unchecked)
1 Answers

Replace your function by this code then it will work well

def search(text):
    text=list(text)
    pat=[]
    history=[]
    for char in text:
        print(char)
        negative=[]
        pat.append(char)
        temp = text.copy()
        for i in range(int(len(text)/len(pat))):
            for char in pat:
                unchecked = temp.pop(0)
                if unchecked == char:
                    history.append(unchecked)
Related