Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
zip_longest, groupby solution in Clear category for Long Pressed by Sim0000
from itertools import groupby, zip_longest
def long_pressed(text: str, typed: str) -> bool:
if text == typed: return False
for (c1, n1), (c2, n2) in zip_longest(groupby(text), groupby(typed), fillvalue=('', [])):
if c1 != c2 or len(list(n1)) > len(list(n2)): return False
return True
print("Example:")
print(long_pressed("alex", "aaleex"))
assert long_pressed("alex", "aaleex") == True
assert long_pressed("welcome to checkio", "weeeelcome to cccheckio") == True
assert long_pressed("there is an error here", "there is an errorrr hereaa") == False
assert long_pressed("hi, my name is...", "hi, my name is...") == False
print("The mission is done! Click 'Check Solution' to earn rewards!")
Sept. 22, 2022