Write a Python program to return the difference between the largest and smallest elements in a given list of integers.
[10, 4, 2, 5, 7]
def diff(nums):
    return max(nums) - min(nums)

print(diff([10, 4, 2, 5, 7])) # 8