Concatenate two separate strings from arrays in a for loop
<p>Okay so I have two lists, they can be anywhere from just one value long to 20, but they will always have the same amount as eachother.</p>

<p>e.g </p>

<pre><code>alphabet = ['a', 'b', 'c', 'd', 'e']
numbers = ['1', '2', '3', '4', '5']
</code></pre>

<p>Now my objective is to create a for loop that would go through both lists, and add the corresponding values from each list to each other. So..</p>

<pre><code>['a1', 'b2', 'c3', 'd4', '5e']
</code></pre>

<p>Just to give another example.</p>

<pre><code>names = ['john', 'harry', 'joe']
IDs = ['100', '200', '300']

output: ['john100', 'harry200', 'joe300']
</code></pre>

<p>Would anyone be able to point me in the right direction? </p>

<p>As an alternative to @Psidom one-liner solution you could just use <code>zip()</code>:</p>

<pre><code>&gt;&gt;&gt;[i+j for i, j in zip(alphabet, numbers)]
&gt;&gt;&gt;['a1', 'b2', 'c3', 'd4', 'e5']
</code></pre>

<p>Or if you perfef to use a regular for loop:</p>

<pre><code>res = []
for i, j in zip(alphabet, numbers):
    res.append(i+j)
</code></pre>

<p>You could also make this more general, and put it in a function:</p>

<pre><code># method one
def concancate_elements(list1, list2):
    return [i+j, for i, j in zip(alphabet, numbers)]

# method two
def concancate_elements(list1, list2):
    res = []
    for i, j in zip(alphabet, numbers):
        res.append(i+j)
    return res
</code></pre>

python concatenation