I have been trying to solve the following problem using Python, and so far without success:
Assume you have a string with the characters '0', '1' and '?'. the '?' sign can be either '0' or '1'. Your goal is to print all the possible outputs for such given string.For example, the output for the string '0?1?' should be '0010', '0011', '0110' and '0111'
I have tried the following:
def comb(S):
if not '?' in S:
yield S
else:
yield comb(S.replace('?','0',1))
yield comb(S.replace('?','1',1))
S = '0?1??011'
S_generator = comb(S)
for s in S_generator:
print s
The result is strange, and is not what I am trying to get:
<generator object comb at 0x106b2ceb0>
<generator object comb at 0x106b2cf00>
Any idea why it is not working, and how I should change the code for this to work?
combfunction seems to return generator object. So third and fourth yield statements in it are taking generator objects. They should take string.