import random def is_continus(nums, k): data = [random.choice(nums) for _ in range(k)] data.sort() print data zero = data.count(0) small, big = zero, zero + 1 while big < k: if data[small] == data[big]: return False tmp = data[big] - data[small] if tmp > 1: if tmp - 1 > zero: return False else: zero -= tmp - 1 small += 1 big += 1 else: small += 1 big += 1 return True