Python Forum
Appending inside elements of lists, in an exact location - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Appending inside elements of lists, in an exact location (/thread-13601.html)



Appending inside elements of lists, in an exact location - nhan826 - Oct-23-2018

In Python, how would I append to an element inside a list in a particular location? Ex.) if I have the list ['*4','*3','*2','*1'] and I want to add the elements [a,b, c] in a cycle, in between. So the result would be ['*a4', '*b3', '*c2', '*a1'].


RE: Appending inside elements of lists, in an exact location - micseydel - Oct-23-2018

Given that you have two lists, you can use zip to iterate over them in parallel, and then you can concatenate in a loop. e.g.
first = "123"
second = "abc"

for num, letter in zip(first, second):
    print(num + letter)