<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def sanitize(s, strict=True):
 """ Sanitize a string. Spaces are converted to underscore; if strict=True they are then removed. Parameters s : str String to sanitize strict : bool If True, only alphanumeric characters are allowed. If False, a limited set of additional characters (-._) will be allowed. """

    allowed = ''.join(
        [
            'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
            'abcdefghijklmnopqrstuvwxyz',
            '0123456789',
        ]
    )

    if not strict:
        allowed += '-_.'

    s = str(s).replace(' ', '_')

    return ''.join([i for i in s if i in allowed])