fork download
  1. from itertools import product
  2.  
  3. def subsl(text, **literals):
  4. return map(
  5. ''.join, product(*[map(str, literals.get(t, t)) for t in text])
  6. )
  7.  
  8. print(
  9. *subsl('x^2+2*x*y+y^2', x=(1,2,3), y=(5,6,7)),
  10. sep='\n'
  11. )
Success #stdin #stdout 0.02s 8736KB
stdin
Standard input is empty
stdout
1^2+2*1*5+5^2
1^2+2*1*5+6^2
1^2+2*1*5+7^2
1^2+2*1*6+5^2
1^2+2*1*6+6^2
1^2+2*1*6+7^2
1^2+2*1*7+5^2
1^2+2*1*7+6^2
1^2+2*1*7+7^2
1^2+2*2*5+5^2
1^2+2*2*5+6^2
1^2+2*2*5+7^2
1^2+2*2*6+5^2
1^2+2*2*6+6^2
1^2+2*2*6+7^2
1^2+2*2*7+5^2
1^2+2*2*7+6^2
1^2+2*2*7+7^2
1^2+2*3*5+5^2
1^2+2*3*5+6^2
1^2+2*3*5+7^2
1^2+2*3*6+5^2
1^2+2*3*6+6^2
1^2+2*3*6+7^2
1^2+2*3*7+5^2
1^2+2*3*7+6^2
1^2+2*3*7+7^2
2^2+2*1*5+5^2
2^2+2*1*5+6^2
2^2+2*1*5+7^2
2^2+2*1*6+5^2
2^2+2*1*6+6^2
2^2+2*1*6+7^2
2^2+2*1*7+5^2
2^2+2*1*7+6^2
2^2+2*1*7+7^2
2^2+2*2*5+5^2
2^2+2*2*5+6^2
2^2+2*2*5+7^2
2^2+2*2*6+5^2
2^2+2*2*6+6^2
2^2+2*2*6+7^2
2^2+2*2*7+5^2
2^2+2*2*7+6^2
2^2+2*2*7+7^2
2^2+2*3*5+5^2
2^2+2*3*5+6^2
2^2+2*3*5+7^2
2^2+2*3*6+5^2
2^2+2*3*6+6^2
2^2+2*3*6+7^2
2^2+2*3*7+5^2
2^2+2*3*7+6^2
2^2+2*3*7+7^2
3^2+2*1*5+5^2
3^2+2*1*5+6^2
3^2+2*1*5+7^2
3^2+2*1*6+5^2
3^2+2*1*6+6^2
3^2+2*1*6+7^2
3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