Advertisement
DiYane

String explosion

Sep 26th, 2023
745
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.66 KB | None | 0 0
  1. def string_explosion(string):
  2.     result = ''
  3.     what_left = 0
  4.     for letter in string:
  5.         if len(letter) > 1 and any(map(str.isdigit, letter)):
  6.             what_left += (int(letter[0]) - 1)
  7.             if what_left >= len(letter):
  8.                 result += ">"
  9.             else:
  10.                 result += ">" + letter[1 + what_left:]
  11.                 what_left = 0
  12.         elif len(letter) == 1 and letter.isdigit():
  13.             if int(letter) > 1:
  14.                 what_left += (int(letter) - 1)
  15.             result += ">"
  16.         else:
  17.             result += letter
  18.  
  19.     return result
  20.  
  21. string = input().split(">")
  22. print(string_explosion(string))
Tags: python
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement