python - Skipping over values in a generator function -
i writing generator function gives me alpha-characters, so,
def gen_alphalabels(): = range(65,91) in a: yield chr(i) k = gen_alphalabels() in range(26): print k.next(), this yields,
a b c d e f g h j k l m n o p q r s t u v w x y z this works....
i function skip on characters in donotinclude list. outside generator, so,
k = gen_alphalabels() donotinclude = ['d','k','j'] in range(26): r = k.next() if r not in donotinclude: print r, this yields desired result of skipping on 'd','k' , 'j'
a b c e f g h l m n o p q r s t u v w x y z is there way include logic relating skipping on characters in generator function? thing along lines of
def gen_alphalabels(): = range(65,91) in a: r = chr(i) if r in donotinclude: yield self.next() else: yield r
without using continue + little shortening of code:
def gen_alphalabels(donotinclude): in range(65,91): char = chr(i) if char not in donotinclude: yield char
Comments
Post a Comment