Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Long Pressed by freeman_lex
from itertools import groupby
def long_pressed(text: str, typed: str) -> bool:
text1 = [list(g) for _, g in groupby(text)]
typed1 = [list(g) for _, g in groupby(typed)]
return all([text != typed,
len(typed1) == len(text1),
*[b[0] == a[0] and len(b) >= len(a) for a, b in zip(text1, typed1)]])
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. 14, 2022