What would be the simplest way to get the next value based on a sorted list?
Sorted list with unique numbers:
If the number n is not found in the list, return n+1, if is found, find in the last number that does not breaks an incremental sequence, return num+1.
- num=1, for the list [1,2,3,6] would return 4.
- num=10, for the list [1,2,3,6] would return 11.
- num=5, for the list [1,2,3,6] would return 7.
I tough about a recursive call, something like:
def nextn(num,listnums):
if(num not in listnums): return num+1
return nextn(num+1,listnums)
listnums=[1,2,3,6]
n=1
nn = nextn(n,listnums)
print("n=%d nn=%d" %(n,nn))