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!
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 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