I have a list of "string indexes" built following this pattern:
allIndexes = ['A', 'B', 'C'... 'Z', 'AA', 'AB',... 'AZ'... 'ZZ', 'AAA', 'AAB'...]
Now, let's say I want to create a new unique index. Here is my code so far:
import string
indexes = ['A', 'AA', 'CB', 'B', 'H', 'IZ']
x = 0
for i in indexes:
if string.ascii_uppercase[x] == i:
x += 1
else:
newIndex = string.ascii_uppercase[x]
print newIndex
>>> C
It works well for the entries from 'A' to 'Z', but how can I make it work for any index following the pattern?
I mean, given an unordered list of "string indexes", how do I find the lowest string index that doesn't appear in that list?
In the code sample, the list contains "A" and "B", so the next lowest string index is "C". But the code fails if the list doesn't contains all string indexes of length 1. Suppose indexes was ["A", "B", ... "Z", "AA"]. Then newIndex
should be "AB".