0

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
2
  • I am not understanding quite well what you are trying to do... Are you trying to add an \n or a 10, because in your script you are inserting the number 10. What are the \ns for? Commented Nov 11, 2016 at 12:43
  • 10 is the decimal number of "\n" Commented Nov 11, 2016 at 17:08

1 Answer 1

2

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)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.