Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.26 KB | None | 0 0
  1. def swap_characters(word, char1, char2):
  2.   translator = {char1: char2, char2: char1}
  3.   new_word = ''
  4.   for c in word:
  5.     try:
  6.       new_word += translator[c]
  7.     except KeyError:
  8.       new_word += c
  9.   return new_word
  10.  
  11. print(swap_characters("wykop", "w", "p"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement