pyassistant

Run-Length Encode a String

Write a function that performs a simple run-length encoding on a string. Given an input string s, return a list of tuples where each tuple contains a character and the number of times that character appears consecutively in s. The order should follow the original string from left to right. If the input string is empty, return an empty list.

Example:

Input:
('aaabbcaaa',)
Output:
[('a', 3), ('b', 2), ('c', 1), ('a', 3)]

Make sure you return your solution, don't print!

AI

Bot

Trying to solve my challenge? Ask if you must, or press the purple button so I can analyze your code.