Skip to content

Instantly share code, notes, and snippets.

@Kagee
Created November 17, 2017 22:22
Show Gist options
  • Save Kagee/3655d49eeb9f1dd01cd9e0b0c6506734 to your computer and use it in GitHub Desktop.
Save Kagee/3655d49eeb9f1dd01cd9e0b0c6506734 to your computer and use it in GitHub Desktop.
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"
@orbekk
Copy link

orbekk commented Nov 17, 2017

def replace(s, a, b):
for (q,t) in zip(a,b):
s = s.replace(q,t)
return s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment