Python Forum

Full Version: Appending inside elements of lists, in an exact location
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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'].
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)