DiYane

Zeros to Back

Aug 9th, 2023 (edited)
925
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.33 KB | None | 0 0
  1. def move_zeros_to_end(input_str):
  2.     integer_list = [int(x) for x in input_str.split(', ')]
  3.  
  4.     zeros = [x for x in integer_list if x == 0]
  5.     non_zeros = [x for x in integer_list if x != 0]
  6.  
  7.     result = non_zeros + zeros
  8.  
  9.     return result
  10.  
  11. input_string = input()
  12.  
  13. output = move_zeros_to_end(input_string)
  14. print(output)
  15.  
Tags: python
Advertisement
Add Comment
Please, Sign In to add comment