Longest run of consecutive values

Write longest_consecutive(nums) that returns the length of the longest sequence of consecutive whole numbers that all appear in nums, in any order and with repeats allowed.

longest_consecutive([100, 4, 200, 1, 3, 2])  ->  4     (1, 2, 3, 4)
longest_consecutive([0, 3, 7, 2, 5, 8, 4, 6, 0, 1])  ->  9
longest_consecutive([])  ->  0

The point is to practise a set that lets you start counting only at the beginning of a run. Sorting also works; the set version is linear.

def longest_consecutive(nums):
    ...