@Phuket2
Just think of using print instead of yield. Anything that gets printed would be yielded. If you wanted to skip printing an item you would use
or alternatively
if some_skip_condition: continue print itemnow replace print with yield and you have a generator. I don't think there are any restrictions on the type of control structures you use in a generator, only that your logic must be correct in the first place. If you had tried something like that and it didn't work, it wouldn't have worked if you used print instead of yield!