def make_python_identifier(string):
    """Takes an arbitrary string and creates a valid Python identifier.
    
    Identifiers must follow the convention outlined here:
    https://docs.python.org/2/reference/lexical_analysis.html#identifiers
    """
    # Todo: check for variable uniqueness -
    # perhaps maintain a list of current variables and their translations??

    string = string.lower()

    # remove leading and trailing whitespace
    string = string.strip()

    # Make spaces into underscores
    string = string.replace(' ', '_')

    # Remove invalid characters
    string = re.sub('[^0-9a-zA-Z_]', '', string)

    # Remove leading characters until we find a letter or underscore
    string = re.sub('^[^a-zA-Z_]+', '', string)

    if keyword.kwlist in string:
        string += '_element'

    return string
dataset/ETHPy150Open JamesPHoughton/pysd/pysd/builder/builder.py/make_python_identifier/swapped operands of `in`