Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def swap_characters(word, char1, char2):
- translator = {char1: char2, char2: char1}
- new_word = ''
- for c in word:
- try:
- new_word += translator[c]
- except KeyError:
- new_word += c
- return new_word
- print(swap_characters("wykop", "w", "p"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement