 <p>While I don't know bash and don't see how <code>permutations</code> would solve your problem, it seems that <code>itertools.product</code> is a fairly straightforward way to do this:</p> <pre><code>&gt;&gt;&gt; s = 'atgc' &gt;&gt;&gt; d = dict(zip(s, 'tacg')) &gt;&gt;&gt; import itertools &gt;&gt;&gt; for i in itertools.product(s, repeat=10): sta = ''.join(i) stb = ''.join(d[x] for x in i) </code></pre> <p>while proposed method is valid in terms of obtaining all possible permutations with replacement of the <code>'atgc'</code> string, i.e., finding <code>sta</code> string, finding <code>stb</code> would be more efficient not through the dictionary look-up, but rather the translation mechanism:</p> <pre><code>&gt;&gt;&gt; trans = str.maketrans(s, 'tacg') &gt;&gt;&gt; for i in itertools.product(s, repeat=10): sta = ''.join(i) stb = sta.translate(trans) </code></pre> <p>Thanks to Dave, for highlighting more efficient solution.</p>