diff --git a/projects/007-run-length-encoding/python/main.py b/projects/007-run-length-encoding/python/main.py index e69de29..00c0994 100644 --- a/projects/007-run-length-encoding/python/main.py +++ b/projects/007-run-length-encoding/python/main.py @@ -0,0 +1,15 @@ +def run_length_encoding(list_to_code): + + if not list_to_code: + return list_to_code + elif len(list_to_code) == 1: + return list_to_code + [1] + else: + number = 1 + letter = list_to_code[0] + count = 1 + + while letter == list_to_code[count]: + number += 1 + count += 1 + return [letter] + [number] + run_length_encoding(list_to_code[count:len(list_to_code)])