0

I have an expression like below: TXTXFX

I need to create different combinations by replacing X by "T" and "F". The expression might change based on the input.

I am using python to do it using lengthy for loops. (not yet achieved it)

Could you please suggest a convenient way to do it in python.

Thanks

1 Answers1

0

It's pretty unclear what you ask, but

t='TXTXFX'

out=[]
for c in ["T","F"]:
  out.append(t.replace("X",c))

gives out:

['TTTTFT', 'TFTFFF']
Johan Lundberg
  • 26,184
  • 12
  • 71
  • 97
  • I am sorry for not making it clear. The output for the above should be: [TFTFFF, TFTFFT, TFTTFF, TFTTFT, TTTFFF, TTTFFT, TTTTFF, TTTTFT]. I need all possible combinations for X. – Vidhi Goel Apr 19 '15 at 18:34