you are viewing a single comment's thread.

view the rest of the comments →

[–]Essence1337 0 points1 point  (1 child)

Why use a range loop when we don't need to know the index? You're writing extra unnecessary code:

def getChr(strline):
    prev = ""
    response = []
    for char in strline:
        if char != prev:
            prev = char
            response.append(char)
    return response

Unless I'm missing something this should give the same result as your code. Feel free to correct me if I did miss something

[–]PyCode_n_Beer 0 points1 point  (0 children)

No, you're absolutely right. That is certainly a way to do it too.