2015-12-23 23:03:40 +01:00
|
|
|
"""
|
|
|
|
This file contains various utility functions.
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
2015-12-25 01:43:49 +01:00
|
|
|
def replaceAll(text, replace_dict):
|
|
|
|
"""
|
|
|
|
Replace all the ``replace_dict`` keys by their associated item in ``text``.
|
|
|
|
"""
|
|
|
|
for i, j in replace_dict.items():
|
2015-12-23 22:49:14 +01:00
|
|
|
text = text.replace(i, j)
|
|
|
|
return text
|
|
|
|
|
|
|
|
|
|
|
|
def clean_whitespaces(text):
|
|
|
|
"""
|
2015-12-25 01:43:49 +01:00
|
|
|
Remove double whitespaces and trailing "." and "," from text.
|
2015-12-23 22:49:14 +01:00
|
|
|
"""
|
|
|
|
return ' '.join(text.strip().rstrip(".,").split())
|