ranges = sum((list(t) for t in zip(nums, nums[1:]) if t[0] + 1 != t[1]), [])
iranges = iter(nums[0:1] + ranges + nums[-1:])
print(', '.join([(str(n) + '-' + str(next(iranges))) for n in iranges]))
Detecting consecutive integers in a list