Write an algorithm in Python to perform a linear search.
arr = [1, 5, 7, 8, 10]
key = 7
def linear_search(arr, key):
    for index, element in enumerate(arr):
        if element == key:
            return index
    return -1

print(linear_search(arr, key))