def escape(s):
    """Replace special characters '&', "'", '<', '>' and '"' by XML entities."""
    s = s.replace("&", "&amp;") # Must be done first!
    s = s.replace("'", "&apos;")
    s = s.replace("<", "&lt;")
    s = s.replace(">", "&gt;")
    s = s.replace('"', "&quot;")
    return s
Replace special characters '&', "'", '<', '>' and '"' by XML entities.
recipes/Python/66003_Converting_list_equal_length_lists/recipe-66003.py