'valid is a list of legal strings'

def __init__(self, key, valid, ignorecase=False):

    self.key = key
    self.ignorecase = ignorecase
    def func(s):
        if ignorecase:
            return s.lower()
        else:
            return s
    self.valid = {func(k): k for k in valid}
