Write a Python code fragment to optimize the given function.
def search(data, x):
    for element in data:
        if element == x:
            return True
    return False
def search(data, x):
    if x in data:
        return True
    return False