You are viewing a single comment's thread. Return to all comments →
Python 3
import itertools def alternate(s): pattern = re.compile(r'^(\w)(?!\1)(\w)(\1\2)*\1?$') letters = set(s) num_letters = len(letters) if num_letters < 2: return 0 maximum = 0 for removals in itertools.combinations(letters, num_letters-2): string = s for letter in removals: string = string.replace(letter, "") if pattern.match(string): maximum = max(maximum, len(string)) return maximum
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 3