> [Run-length encoding](https://en.wikipedia.org/w/index.php?title=Run-length_encoding) (RLE) is a very simple form of data compression in which runs of data (that is, sequences in which the same data value occurs in many consecutive data elements) are stored as a single data value and count, rather than as the original run. Wikipedia

## Task

Your task is to write such a run-length encoding. For a given string, return a list (or array) of pairs (or arrays) 
[
 (i1, s1),
 (i2, s2),
 …,
 (in, sn)
], such that one can reconstruct the original string by replicating the character sx ix times and concatening all those strings. Your run-length encoding should be minimal, ie. for all i the values si and si+1 should differ.

## Examples

As the article states, RLE is a _very_ simple form of data compression. It's only suitable for runs of data, as one can see in the following example:

```python
run_length_encoding("hello world!")
 //=>      [[1,'h'], [1,'e'], [2,'l'], [1,'o'], [1,' '], [1,'w'], [1,'o'], [1,'r'], [1,'l'], [1,'d'], [1,'!']]
```

It's very effective if the same data value occurs in many consecutive data elements:
```python
run_length_encoding("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbb")
# => [[34,'a'], [3,'b']]
```

Difficulty: EASY
Starter code: def run_length_encoding(s):
	

Solutions:
from itertools import groupby

def run_length_encoding(s):
	return [[sum((1 for _ in g)), c] for (c, g) in groupby(s)]


from itertools import groupby

def run_length_encoding(s):
	return [[len(list(b)), a] for (a, b) in groupby(s)]


def run_length_encoding(s):
	(count, prev, lst) = (1, '', [])
	for c in s:
		if c != prev:
			if prev:
				lst.append([count, prev])
			(count, prev) = (1, c)
		else:
			count += 1
	if len(prev) > 0:
		lst.append([count, prev])
	return lst


from itertools import groupby

def run_length_encoding(s):
	return [[len(list(g)), k] for (k, g) in groupby(s)]


import re

def run_length_encoding(s):
	return [[len(l), e] for (l, e) in re.findall('((.)\\2*)', s)]


from itertools import groupby
import re

def run_length_encoding(s):
	return [[len(list(j)), i] for (i, j) in groupby(s)]
	return [[len(i), j] for (i, j) in re.findall('((.)\\2*)', s)]


from itertools import groupby

def run_length_encoding(s):
	return [[len(list(gp)), x] for (x, gp) in groupby(s)]


from re import findall

def run_length_encoding(string):
	return [[len(a), b] for (a, b) in findall('((.)\\2*)', string)]


def run_length_encoding(s):
	result = []
	if s:
		prev = s[0]
		count = 1
		for ind in range(1, len(s)):
			if s[ind] == prev:
				count += 1
			else:
				result.append([count, prev])
				prev = s[ind]
				count = 1
		result.append([count, prev])
	return result


import re

def run_length_encoding(s):
	ls = re.finditer('(.)\\1*', s)
	t = []
	for i in ls:
		t.append([i.end() - i.start(), i.group()[0]])
	return t


def run_length_encoding(s):
	rle = []
	for (i, ch) in enumerate(s):
		if i == 0:
			rle.append([1, ch])
		else:
			last_ch = rle[-1][1]
			if last_ch == ch:
				new_count = rle[-1][0] + 1
				rle.pop()
				rle.append([new_count, ch])
			else:
				rle.append([1, ch])
	return rle


def run_length_encoding(s):
	ret = []
	p = None
	for c in s:
		if c == p:
			ret[-1][0] += 1
		else:
			ret.append([1, c])
			p = c
	return ret


def run_length_encoding(s):
	result = []
	i = j = 0
	while i < len(s):
		while j < len(s) and s[i] == s[j]:
			j += 1
		result.append([j - i, s[i]])
		i = j
	return result


def run_length_encoding(string):
	code = []
	for c in string:
		if not code or code[-1][1] != c:
			code.append([1, c])
		else:
			code[-1][0] += 1
	return code


from itertools import groupby

def run_length_encoding(s):
	encoded_s = []
	key = lambda x: x[0]
	for (k, g) in groupby(s, key):
		encoded_s.append([len(list(g)), k])
	return encoded_s


def run_length_encoding(s):
	if len(s) == 0:
		return []
	encoded_s = [[1, s[0]]]
	last_char = s[0]
	for char in s[1:]:
		if char == last_char:
			encoded_s[-1][0] = encoded_s[-1][0] + 1
		else:
			encoded_s.append([1, char])
		last_char = char
	return encoded_s


def run_length_encoding(s):
	if len(s) == 0:
		return []
	cnt = 1
	prev = s[0]
	out = []
	s = s + ' '
	for i in range(len(s) - 1):
		if s[i + 1] == prev:
			cnt = cnt + 1
		elif cnt > 1:
			out.append([cnt, prev])
			cnt = 1
		else:
			out.append([1, prev])
		prev = s[i + 1]
	return out