Answer to Question #283510 in Python for Rishu Pandey

Question #283510

Given a string, write a program to move all the numbers in it to its start.


1
Expert's answer
2021-12-29T17:51:38-0500
def move_numbers(S):
    numbers = ''
    not_numbers = ''
    in_number = False
    for ch in s:
        if '0' <= ch <= '9':
            numbers += ch
            in_number = True
        elif ch == ' ' and in_number:
            numbers += ch
            in_number = False
        else:
            not_numbers += ch
            in_number = False
    return numbers + not_numbers

s = '33 cows can graze a field in 12 days. How many cows will graze the same field in 9 days?​'
s = move_numbers(s)
print(s)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS