In: Computer Science
In python write a program which prints the longest substring of numbers which occur in ascending order
s=342153476757561235
main.py:
import itertools
def letters_pairs(iterable):
n1, n2 = itertools.tee(iterable)
next(n2, None)
yield from itertools.zip_longest(n1, n2, fillvalue='')
def alphabetical_Strings(str):
arr = []
for characters, nxt_char in letters_pairs(str):
arr.append(characters)
if characters > nxt_char:
yield ''.join(arr)
arr.clear()
def sorted_long_substrings(str):
return max(alphabetical_Strings(str), key=len)
if __name__ == '__main__':
print("The longest substring is: "+sorted_long_substrings('342153476757561235'))
Indentation:
Output: