Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Assuming you have two lists of equal length, you can use the built-in zip() function to iterate through both lists simultaneously, then append each item to a new list twice:

list1 = [1, 2, 3, 4] list2 = ['a', 'b', 'c', 'd'] duplicated_list = [] for item1, item2 in zip(list1, list2): duplicated_list.append(item1) duplicated_list.append(item2) print(duplicated_list) 

Output:

[1, 'a', 2, 'b', 3, 'c', 4, 'd']

In this example, we create two lists list1 and list2, then iterate over both of them using zip(). In each iteration, we append the current value from list1 and list2 to the duplicated_list twice. Finally, we print duplicated_list which contains all the items from both original lists duplicated.