I am writing a generator function that gives me alpha characters like
def gen_alphaLabels(): a = range(65,91) for i in a: yield chr(i) k = gen_alphaLabels() for i in range(26): print k.next(),
This gives,
ABCDEFGHIJKLMNOPQRSTU VWXYZ
It works....
I could skip some of the characters in the donotInclude list. I could do this outside the generator, for example,
k = gen_alphaLabels() donotInclude = ['D','K','J'] for i in range(26): r = k.next() if r not in donotInclude: print r,
This gives the desired result of skipping over 'D', 'K' and 'J'
ABCEFGHILMNOPQRSTUVWX YZ
Is there a way to enable logic related to skipping characters in generator functions? Something like
def gen_alphaLabels(): a = range(65,91) for i in a: r = chr(i) if r in donotInclude: yield self.next() else: yield r
nitin source share