Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
next and try within a while solution in Clear category for Beat The Previous by joe_5588
def beat_previous(digits: str) -> list[int]:
curr = ''
# create an iterator over digits
iter_digits = iter(digits)
# use next to get the first value from the iterator
output = [int(next(iter_digits))]
while True:
# keep trying to get the next value
try:
curr += next(iter_digits)
if int(curr) > output[-1]:
output += [int(curr)]
curr = ''
# return the output if we have reached the end of the iterator
except StopIteration:
return output
Sept. 25, 2023
Comments: