Created
May 20, 2013 08:42
-
-
Save xfenix/5611090 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
def str_replace_multi(string, replacements, empty_if_list=True): | |
try: | |
iterator = repls.iteritems() | |
except: | |
if isinstance(replacements, (list, tuple)): | |
first = iter(replacements) | |
second = ['']*len(replacements) if empty_if_list else\ | |
first | |
iterator = dict(zip(first, second)) | |
else: | |
return string | |
return reduce(lambda a, kv: a.replace(*kv), iterator, string) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment