Given a string of integers, count how many times that integer repeats itself, then return a string showing the count and the integer.


Example: `countMe('1123')` (`count_me` in Ruby)

- Here 1 comes twice so `` will be `"21"`
- then 2 comes once so `` will be `"12"`
- then 3 comes once so `` will be `"13"`

hence output string will be `"211213"`.


Similarly `countMe('211213')` will return `'1221121113'`
(1 time 2, 2 times 1, 1 time 2, 1 time 1, 1 time 3)


Return `""` for empty, nil or non numeric strings

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Starter code: def count_me(data):
	

Solutions:
def count_me(data):
	if not data.isdigit():
		return ''
	result = []
	count = 1
	last = data[0]
	for char in data[1:]:
		if char == last:
			count += 1
		else:
			result.append(str(count) + last)
			last = char
			count = 1
	result.append(str(count) + last)
	return ''.join(result)


from re import search, sub, findall
count_me = lambda s: '' if search('[^0-9]', s) != None else sub('(.)\\1*', lambda m: str(len(m.group(0))) + m.group(1), s)


count_me = lambda s: __import__('re').sub('(\\d)\\1*', lambda x: f'{len(x.group())}{x.group(1)}', s) * s.isdigit()


from itertools import groupby

def count_me(s):
	return ''.join((str(sum((1 for _ in y))) + x for (x, y) in groupby(s))) if s.isdigit() else ''


from itertools import groupby

def count_me(data):
	if not data.isdecimal():
		return ''
	groups = [''.join(g) for (_, g) in groupby(data)]
	return ''.join((f'{len(g)}{g[0]}' for g in groups))


def count_me(data):
	if not data.isdigit():
		return ''
	output = ''
	from itertools import groupby
	for (k, v) in groupby(data):
		output += str(len(list(v))) + k
	return output


from itertools import groupby

def count_me(data):
	return ''.join((str(len(list(g))) + k for (k, g) in groupby(data))) if data.isdecimal() else ''


count_me = lambda s: s.isdigit() and ''.join((str(len(list(g))) + k for (k, g) in __import__('itertools').groupby(s))) or ''


from itertools import groupby
import re

def count_me(data):
	s = ''.join((str(len(list(g))) + k for (k, g) in groupby(data)))
	return s if re.search('[a-zA-Z]', s) is None else ''