Created
November 17, 2017 22:22
-
-
Save Kagee/3655d49eeb9f1dd01cd9e0b0c6506734 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
what happens: | |
>>> a = [ "ø", "å" ] | |
b = [ "\\x{F8}", "\\x{E5}" ] | |
>>> b | |
['\\x{F8}', '\\x{E5}'] | |
>>> "øremål".replace(a,b) | |
Traceback (most recent call last): | |
get_non_ascii(): | |
File "<stdin>", line 1, in <module> | |
TypeError: Can't convert 'list' object to str implicitly | |
what i want: | |
>>> a = [ "ø", "å" ] | |
b = [ "\\x{F8}", "\\x{E5}" ] | |
>>> b | |
['\\x{F8}', '\\x{E5}'] | |
>>> "øremål".replace(a,b) | |
"\\x{F8}rem\\x{E5}l" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
def replace(s, a, b):
for (q,t) in zip(a,b):
s = s.replace(q,t)
return s