Simple Recursive Generator Question
Skip Montanaro
skip at pobox.com
Fri Dec 19 16:08:12 EST 2003
More information about the Python-list mailing list
Fri Dec 19 16:08:12 EST 2003
- Previous message (by thread): Simple Recursive Generator Question
- Next message (by thread): Simple Recursive Generator Question
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
jcb> This is what I have, but it does not work.
jcb> def bitIndexGenerator(mask, index=0):
jcb> if mask == 0: return
jcb> elif mask & 0x1: yield index
jcb> bitIndexGenerator(mask >> 1, index+1)
Try:
def bitIndexGenerator(mask, index=0):
if mask == 0:
return
elif mask & 0x1:
yield index
for index in bitIndexGenerator(mask >> 1, index+1):
yield index
Skip
- Previous message (by thread): Simple Recursive Generator Question
- Next message (by thread): Simple Recursive Generator Question
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list