[Run-length encoding](http://en.wikipedia.org/wiki/Run-length_encoding) (RLE) is a very simple form of lossless data compression in which runs of data are stored as a single data value and count.

A simple form of RLE would encode the string `"AAABBBCCCD"` as `"3A3B3C1D"` meaning, first there are `3 A`, then `3 B`, then `3 C` and last there is `1 D`.

Your task is to write a RLE encoder and decoder using this technique. The texts to encode will always consist of only uppercase characters, no numbers.

Source: codewars | Difficulty: EASY

Starter code: def encode(string):
	

Solutions:
from re import sub

def encode(string):
	return sub('(.)\\1*', lambda m: str(len(m.group(0))) + m.group(1), string)

def decode(string):
	return sub('(\\d+)(\\D)', lambda m: m.group(2) * int(m.group(1)), string)


encode = lambda s: ''.join((f'{len(list(group))}{char}' for (char, group) in __import__('itertools').groupby(s)))
decode = lambda s: ''.join((c * int(n) for (n, c) in __import__('re').findall('(\\d+)(\\D{1})', s)))


import re

def encode(s):
	return ''.join((f'{len(g)}{c}' for (g, c) in re.findall('((.)\\2*)', s)))

def decode(s):
	return ''.join((int(n) * c for (n, c) in re.findall('(\\d+)(\\w)', s)))


import re

def encode(st):
	return ''.join((f'{len(e.group())}{e.group()[0]}' for e in re.finditer('(.)\\1*', st)))

def decode(st):
	return re.sub('(\\d+\\w)', lambda x: x.group()[-1] * int(x.group()[:-1]), st)


def encode(string):
	from itertools import groupby
	encode_group = '{group_length}{char}'.format
	return ''.join([encode_group(group_length=len(tuple(group)), char=char) for (char, group) in groupby(string)])

def decode(string):
	import re
	encoded_group = re.compile('(?P<group_length>\\d+)(?P<char>[A-Z])')
	return re.sub(pattern=encoded_group, repl=lambda match: int(match.group('group_length')) * match.group('char'), string=string)


from itertools import groupby

def encode(string):
	return ''.join([f'{len(list(g))}{k}' for (k, g) in groupby(string)])

def decode(string):
	number = ''
	result = []
	for i in string:
		if i in '1234567890':
			number += i
		else:
			result += [i] * int(number)
			number = ''
	return ''.join(result)


from itertools import groupby as g
encode = lambda s: ''.join(('%s%s' % (sum((1 for _ in v)), k) for (k, v) in g(s)))
decode = lambda s: ''.join((int(d) * c for (d, c) in zip(*[iter((''.join(v) for (_, v) in g(s, key=str.isdigit)))] * 2)))


def encode(string):
	a = ''
	c = 0
	r = ''
	for e in string:
		if e == a:
			c += 1
		else:
			if c > 0:
				r = r + str(c) + a
			a = e
			c = 1
	r = r + str(c) + a
	return r

def decode(string):
	c = 0
	r = ''
	for e in string:
		if e.isdigit():
			c = c * 10 + int(e)
		else:
			r = r + e * c
			c = 0
	return r