Advertisement
exDotaPro

string_manipulator

Aug 5th, 2020
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.11 KB | None | 0 0
  1. def translate(char, replacement, my_string):
  2.     return my_string.replace(char, replacement)
  3.  
  4.  
  5. def includes(sub_string, my_string):
  6.     return sub_string in my_string
  7.  
  8.  
  9. def start_with(sub_string, my_string):
  10.     return my_string.startswith(sub_string)
  11.  
  12.  
  13. def find_last_idx(char, my_string):
  14.     return my_string.rfind(char)
  15.  
  16.  
  17. def remove_substring(start_idx, count, my_string):
  18.     my_string = my_string[:start_idx] + my_string[count:]
  19.     return my_string
  20.  
  21.  
  22. string = input()
  23.  
  24. while True:
  25.     line = input().split()
  26.     command = line[0]
  27.  
  28.     if command == 'End':
  29.         break
  30.  
  31.     if command == 'Translate':
  32.         string = translate(line[1], line[2], string)
  33.         print(string)
  34.     elif command == 'Includes':
  35.         print(includes(line[1], string))
  36.     elif command == 'Start':
  37.         print(start_with(line[1], string))
  38.     elif command == 'Lowercase':
  39.         string = string.lower()
  40.         print(string)
  41.     elif command == 'FindIndex':
  42.         print(find_last_idx(line[1], string))
  43.     elif command == 'Remove':
  44.         print(remove_substring(int(line[1]), int(line[2]), string))
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement