Generate a correct python program to fulfill the following purpose:
Count the occurrence of an element x in a list y.
def count_x(x, y):
    count = 0
    for i in range(y):
        if i == x:
            count += 1
    return count