<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def sqlalchemy_escape(val, escape_char, special_chars):
 """Escape a string according for use in LIKE operator 'text\_table' """

    if sys.version_info[:2] >= (3, 0):
        assert isinstance(val, str)
    else:
        assert isinstance(val, basestring)
    result = []
    for c in val:
        if c in special_chars + escape_char:
            result.extend(escape_char + c)
        else:
            result.extend(c)
    return ''.join(result)