Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Groupby solution in Clear category for Count And Say by amandel
from itertools import groupby
def count_and_say(digits: str) -> str:
return ''.join('{}{}'.format(sum(1 for _ in l),d) for d,l in groupby(digits))
print("Example:")
print(count_and_say("123"))
# These "asserts" are used for self-checking
assert count_and_say("333388822211177") == "4338323127"
assert count_and_say("1") == "11"
assert count_and_say("") == ""
print("The mission is done! Click 'Check Solution' to earn rewards!")
Dec. 8, 2023
Comments: