user6788263
user6788263

Reputation:

Python "parser" not working

I was trying to create a Hexviewer in Python (3), while coding, I issued an error that I couldn't fix, I am trying to make a function, that gets in a "\n" every [fontsize]/500, but it is just making "\n"s all over the place, what did I do wrong? (Python 3.4.3)

def parse(parse0):
    parse0 = list(parse0)
    i = 0
    for cur in parse0:
        if not cur == 10:
            i += 1
        else:
            i = 0
        if i > 500/fontsize:
            parse0.insert(parse0.index(cur),10)
            i = 0
    return parse0

Upvotes: 0

Views: 644

Answers (1)

woockashek
woockashek

Reputation: 1628

You shouldn't modify the list during iteration on its elements.

Make a new empty list and insert there your elements (and \n's) one by one in your loop)

Upvotes: 2

Related Questions