Ask Question
15 April, 00:48

Given the lists list1 and list2 that are of the same length, create a new list consisting of the first element of list1 followed by the first element of list2, followed by the second element of list1, followed by the second element of list2, and so on (in other words the new list should consist of alternating elements of list1 and list2). For example, if list1 contained [1, 2, 3] and list2 contained [4, 5, 6], then the new list should contain [1, 4, 2, 5, 3, 6]. Associate the new list with the variable list3.

+4
Answers (1)
  1. 15 April, 02:48
    0
    Below are the program in python language:

    Explanation:

    list1=[1,2,3]#first list which holds the numbers.

    list2=[4,5,6]#second list which holds the numbers.

    list3=[]#third list which is declared.

    for (x, y) in zip (list1, list2) : #for loop which tranverse the both list.

    list3. append (x) #append the first list element.

    list3. append (y) #append the second list element.

    #end the body of the for loop.

    Output:

    The above code assigns the value in the list3 variable in the scenario, on which the question demands.

    Code Explantion:

    The above code is in python language, in which there are two lists in which value can be changed by the user. There is a for loop which scans both the list and appends both list items on the third list like one element from the first list and the other element from the second list.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Given the lists list1 and list2 that are of the same length, create a new list consisting of the first element of list1 followed by the ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers