Guest User

Untitled

a guest
Nov 18th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. """
  2.  
  3. Replace all spaces in a string with %20
  4.  
  5.  
  6. """
  7.  
  8. def replace_spaces(st):
  9. char_list = []
  10.  
  11. for ch in st:
  12. if ch == ' ':
  13. ch = '%20'
  14. char_list.append(ch)
  15.  
  16. return ''.join(char_list)
  17.  
  18.  
  19. if __name__ == "__main__":
  20. TEST_DATA = [
  21. ["I am Keisuke Tsukamoto", "I%20am%20Keisuke%20Tsukamoto"]
  22. ]
  23.  
  24. for st, expected in TEST_DATA:
  25. print(replace_spaces(st) == expected)
Add Comment
Please, Sign In to add comment