You are viewing a single comment's thread. Return to all comments →
python
def alternate(s): from itertools import combinations myset = set(s) if len(myset) < 2: return 0 if len(s) == 2 and len(s) == len(myset): return 2 res = 0 pattern = r'^(.)(?!\1)(.)(\1\2)*\1?$' combs = list(combinations(set(s), len(myset) - 2)) tmp = s for comb in combs: tmp = s for char in comb: tmp = tmp.replace(char, '') if bool(re.match(pattern, tmp)): res = max(res, len(tmp)) return res
Seems like cookies are disabled on this browser, please enable them to open this website
Two Characters
You are viewing a single comment's thread. Return to all comments →
python