Question

In: Computer Science

In python write a program which prints the longest substring of numbers which occur in ascending...

In python write a program which prints the longest substring of numbers which occur in ascending order

s=342153476757561235

Solutions

Expert Solution

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:


Related Solutions

Python Assume s is a string of numbers. Write a program that prints the longest substring...
Python Assume s is a string of numbers. Write a program that prints the longest substring of s in which the numbers occur in ascending order and compute the average of the numbers found. For example, if s = '561984235272145785310', then your program should print: Longest substring in numeric ascending order is: 14578 Average: 5 In the case of ties, print the first substring. For example, if s = '147279', then your program should print Longest substring in numeric ascending...
Assume s is a string of numbers. Write a program that prints the longest substring of...
Assume s is a string of numbers. Write a program that prints the longest substring of s in which the numbers occur in ascending order and compute the average of the numbers found. For example, if s = '561984235272145785310', then your program should print Longest substring in numeric ascending order is: 14578 Average: 5 In the case of ties, print the first substring. For example, if s = '147279', then your program should print Longest substring in numeric ascending order...
Intro to Python! 1. Using while loops, write a program that prints multiples of 5 which...
Intro to Python! 1. Using while loops, write a program that prints multiples of 5 which are less than 100. Your loop initially starts from 0. 2. Consider B to be a list of alphabetically ordered strings. Using while loops, write a program that only prints words which start with letter A. B = [Alex, Airplane, Alpha, Australia, Ben, Book, Bank, Circuit, Count, Dark] 3. Using while loop, create a program that only prints first 18 multiples of 7.Hint: Your...
One Problem/Question (Four Parts) Write a python program which prints a sequence of integers that are...
One Problem/Question (Four Parts) Write a python program which prints a sequence of integers that are multiples of 10, starting at 0 and ending at 100. Write a python program that computes the average of 10 random odd integers, ranging from 0 to 500. Write a python program that prints whatever the user enters, and stops when the user types “done”, using an infinite loop and a break statement. Same as number three but use a condition. The loop terminates...
Write a Python program that reads in an amount in cents and prints the dollar amount...
Write a Python program that reads in an amount in cents and prints the dollar amount in that and the remaining value in cents. For example, if the amount reads in is 360 (cents), the program would print 3 dollars and 60 cents. if the amount read in is 75 (cents), the program would print 0 dollars and 75 cents.
Write a program in python language, which accepts 2 numbers and a + sign (for addition)...
Write a program in python language, which accepts 2 numbers and a + sign (for addition) A sign - (for subtraction) A sign * (for multiplication), / (for division) Then calculate and to display the result of the operation he chose with the two numbers. Displaying the appropriate message
Write a program that computes and prints the average of numbers in a text file. I...
Write a program that computes and prints the average of numbers in a text file. I created a text file integers.txt that has the numbers 5,4,3,2,1. I need to define the average function Define the main function which will include the following things 1. prompt user for input of text file name 2. open and read input file, can be done before or inside high order functions 3. use two high order functions 4.calculate and display averages and original ist...
python Write a program that prints your name 100 times to the screen. Write a function...
python Write a program that prints your name 100 times to the screen. Write a function that takes a string s and an integer n as parameters and prints the string s a total of n times (once per line). Write a for loop that prints all the integers from 3141 to 5926, skipping every other one. Write a for loop that prints every 5th integer from 5926 down to 3141. Write a program (using a for loop) to print...
In Python write a program that calculates and prints out bills of the city water company....
In Python write a program that calculates and prints out bills of the city water company. The water rates vary, depending on whether the bill is for home use, commercial use, or industrial use. A code of r means residential use, a code of c means commercial use, and a code of i means industrial use. Any other code should be treated as an error. The water rates are computed as follows:Three types of customers and their billing rates: Code...
Python # Write a program that examines three variables—x, y, and z # and prints the...
Python # Write a program that examines three variables—x, y, and z # and prints the largest odd number among them. # If none of them are odd, it should print a message to that effect. n = input('Enter the 1st Integer x: ') x = int(n) n = input('Enter the 2nd Integer y: ') y = int(n) n = input('Enter the 3rd Integer z: ') z = int(n) if x % 2 == 0 and y % 2 ==...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT