Similar to the [previous kata](https://www.codewars.com/kata/string-subpattern-recognition-ii/), but this time you need to operate with shuffled strings to identify if they are composed repeating a subpattern

Since there is no deterministic way to tell which pattern was really the original one among all the possible permutations of a fitting subpattern, return a subpattern with sorted characters, otherwise return the base string with sorted characters (you might consider this case as an edge case, with the subpattern being repeated only once and thus equalling the original input string).

For example:

```python
has_subpattern("a") == "a"; #no repeated pattern, just one character
has_subpattern("aaaa") == "a" #just one character repeated
has_subpattern("abcd") == "abcd" #base pattern equals the string itself, no repetitions
has_subpattern("babababababababa") == "ab" #remember to return the base string sorted"
has_subpattern("bbabbaaabbaaaabb") == "ab" #same as above, just shuffled
```

If you liked it, go for either the [previous kata](https://www.codewars.com/kata/string-subpattern-recognition-ii/) or the [next kata](https://www.codewars.com/kata/string-subpattern-recognition-iv/) of the series!

Difficulty: EASY
Starter code: def has_subpattern(string):
	

Solutions:
from collections import Counter
from functools import reduce
from math import gcd

def has_subpattern(string):
	count = Counter(string)
	n = reduce(gcd, count.values())
	return ''.join(sorted((c * (i // n) for (c, i) in count.items())))


from functools import reduce as R
from collections import Counter as C
from math import gcd as G

def has_subpattern(s):
	s = C(s)
	k = R(G, set(s.values()))
	li = [i * (j // k) for (i, j) in s.items()]
	return ''.join(sorted(li))


from collections import Counter
from functools import reduce
from math import gcd

def has_subpattern(string):
	c = Counter(string)
	m = reduce(gcd, c.values())
	for key in c:
		c[key] //= m
	return ''.join(sorted(c.elements()))


from collections import Counter
from functools import reduce
gcd = lambda a, b: gcd(b, a % b) if b else a
has_subpattern = lambda s: (lambda r: (lambda g: ''.join((k * (v // g) for (k, v) in sorted(r.items()))))(reduce(gcd, r.values())))(Counter(s))


from collections import Counter
from math import gcd
from functools import reduce

def has_subpattern(string):
	cnt = Counter(string)
	v = reduce(gcd, cnt.values())
	return ''.join(sorted((k * (n // v) for (k, n) in cnt.items())))


from collections import Counter
from functools import reduce
from math import gcd

def has_subpattern(string):
	if len(string) < 2:
		return string
	c = Counter(string)
	x = reduce(gcd, c.values())
	if x == 1:
		return ''.join(sorted(string))
	return ''.join((k * (c[k] // x) for k in sorted(c.keys())))


from collections import Counter
from functools import reduce
from math import gcd

def has_subpattern(string):
	chars_frequency = Counter(string)
	greatercd = reduce(gcd, chars_frequency.values())
	charslist = sorted(chars_frequency.items())
	pattern = ''
	for (char, frequency) in charslist:
		pattern += char * (frequency // greatercd)
	return pattern


from math import gcd
from functools import reduce

def has_subpattern(s):
	d = {k: s.count(k) for k in set(s)}
	g = reduce(gcd, d.values())
	return ''.join(sorted((k * (v // g) for (k, v) in d.items())))