print([[i+j for i in "abc"] for j in "def"])
<p>I'm new to Python.</p>

<p>I stumped upon with one of this comprehension</p>

<pre><code>print([[i+j for i in "abc"] for j in "def"])
</code></pre>

<p>Could you please help me convert the comprehension in for loop?</p>

<p>I'm not getting the desired result by for loop:</p>

<pre><code>list = []
list2 = []

for j in 'def':
    for i in 'abc':
        list.append(i+j)
    list2 = list
print (list)
</code></pre>

<p>the above is my try with for loop. I' missing something. Below should be the desired result in for loop that i want.</p>

<p><code>([[âadâ, âbdâ, âcdâ], [âaeâ, âbeâ, âceâ], [âafâ, âbfâ, âcfâ]])</code></p>

<p>which I believe is a matrice. </p>

<p>Thanks in advance.</p>

<pre><code>a = 'abc'
b = 'def'

&gt;&gt;&gt; [[x+y for x in a]for y in b]
[['ad', 'bd', 'cd'], ['ae', 'be', 'ce'], ['af', 'bf', 'cf']]
</code></pre>

<h2>Loop</h2>

<pre><code>&gt;&gt;&gt; for y in b:
...     for x in a:
...         print x+y,
... 
ad bd cd ae be ce af bf cf
</code></pre>

python list-comprehension