1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Vinvika [58]
3 years ago
10

Given the lists list1 and list2, not necessarily of the same length, create a new list consisting of alternating elements of lis

t1 and list2 (that is, 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. Once the end of either list is reached, the remaining elements of the longer list is added to the end of the new list. For example, if list1 contained [1, 2, 3] and list2 contained [4, 5, 6, 7, 8], then the new list should contain [1, 4, 2, 5, 3, 6, 7, 8]. Associate the new list with the variable list3.
Computers and Technology
1 answer:
tester [92]3 years ago
5 0

Answer:

The following code is written in Python Programming Language.

Program:

list1=[1,2,3]

 # initialized the list type variable

list2=[4,5,6,7,8]

  # initialized the list type variable

list3=[]

   # initialized the empty list type variable

for j in range(max(len(list1), len(list2))):   #set for loop

 if j<len(list1):

  #set if statement

   list3.append(list1[j])

  #value of list1 appends in list3  

 if j<len(list2):

   #set if statement

   list3.append(list2[j])

  #value of list2 append in list3

print(list3)    #print the list of list3

Output:

[1, 4, 2, 5, 3, 6, 7, 8]

Explanation:

Here, we define three list type variables "list1", "list2", "list3" and we assign value in only first two variables "list1" to [1, 2, 3] and "list2" to [4, 5, 6, 7, 8] and third list is empty.

Then, we set the for loop and pass the condition inside it we pass two if conditions, in first one we compare the list1 from variable "j" inside it the value in list1 will append in list3, and in second one we compare "j" with list two and follow the same process.

After all, we print the list of the variable "list3".

You might be interested in
Merge arrays A and B into array C using merge sort algorithm. Give final sorted numbers of C using colored numbers without showi
sweet-ann [11.9K]

Answer:

Explanation:

Given code:-

#include<iostream>

using namespace std; //namespace

#define RED "\033[31m" /* Red */

#define BLUE "\033[34m" /* Blue */ //color definition

#define WHITE "\033[37m" /* White */

void mergeArrays(int arr1[], int arr2[], int n1, int n2, int arr3[])

//merger sort

{

int i = 0, j = 0, k = 0;

while (i<n1 && j <n2) //iterate over both array

{

if (arr1[i] < arr2[j]) //iff array 1 element is larger

{

arr3[k] = arr1[i]; //assign to a3

k++;

i++;

}

else

{

arr3[k] = arr2[j]; //else assign array 2 to a3

j++;

k++;

}

}

//say the array turns out to br of different sizes

//let us copy the remaining elemnt to array 3

while (i < n1)

{

arr3[k] = arr1[i];

i++;

k++;

}

while (j < n2)

{

arr3[k] = arr2[j];

k++;

j++;

}

}

int main(){

int A[4] = {3,5,7,9}; //array 1 assignment

int a_size = 4;

int b_size = 6;

int B[6] = {1,3,7,9,13,25}; //array 2 assignment

int C[10]; //array 3 declearation

int a_count = 0;

int b_count = 0; //counter for both array index

mergeArrays(A,B,a_size,b_size,C); //merger function applied;

cout<<WHITE<<"A: ";

for(int i = 0; i<4; i++){

cout<<RED<<A[i]<<" ";

}

cout<<endl<<WHITE<<"B: ";

for(int i = 0; i<6; i++){

cout<<BLUE<<B[i]<<" ";

}

cout<<endl<<WHITE<<"C: ";

for(int i = 0; i<10; i++){ //iterate over C

if(C[i] == A[a_count] && a_count < a_size){

cout<<RED<<C[i]<<" ";

// if element is common in array 1 print in red

a_count++;

}

else if (C[i] == B[b_count] && b_count < b_size){

//say element was similar in array 2,  print in blue

cout<<BLUE<<C[i]<<" ";

b_count++;

}

}

cout<<endl;

}

7 0
3 years ago
PLEASE HELP ME
Leto [7]

The steps to executing the above Desktop Publishing  assignment is as follows:

  1. Open Mic. rosoft Word on your computer
  2. Highlight the referenced text and paste onto the empty work space
  3. Highlight all the text using CTRL + A
  4. Navigate to the Justification Button/ Tool as shown in the image and click
  5. While keeping the text highlighted, click on the "Line and Spacing Tool" as indicated in the image
  6. Select the "1.5" spacing action button
  7. Use CTRL + S to save your work.

<h3>What is desktop publishing?</h3>

Desktop publishing is the process of creating documents on a computer using page layout software. It was virtually solely used for print publications at initially, but it now now aids in the development of numerous types of web material.

A desktop publishing software (DTS), sometimes known as a "page layout program" or "publishing program," has full page design features, such as magazine-style columns, rules and borders, page, chapter, and caption numbering, and accurate typographic alignment.

Learn more about desktop publishing:
brainly.com/question/7221277
#SPJ1

8 0
1 year ago
Which of the following should be considered when conducting an audience analysis ?
lyudmila [28]
1. Think about it
2. Interview the event organizer
3. Interview audiance members
4. Survey your audience members
5. <span>Poll people similar to your audience.
</span>6. <span>Study past event archives.
</span>7. Review current event materials
8. Make observations at the event itself
9. <span>Make observations during your presentation
hope this helps</span>
6 0
3 years ago
Read 2 more answers
Write a program to enter a number and test if it is greater than 45.6. If the number entered is greater than 45.6, the program n
Sunny_sXe [5.5K]
Here is the solution. Let me know if you have any question

5 0
3 years ago
Choose the missing term.
qaws [65]

Answer:

import

Explanation:

the <em>import </em>keyword is used to import external modules into a python script.

6 0
2 years ago
Other questions:
  • Click to move a stacked object to the top of the stack?
    8·1 answer
  • Say our confusion matrix is as follows, calculate precision, recall, and accuracy. Interpret the results for the positive class.
    10·1 answer
  • What is the rarest Supercar/hypercar you have ever seen?
    7·1 answer
  • The memory unit of a computer has 256k words of 32 bits each. The computer has an instruction format with 4 fields: an opcode fi
    15·1 answer
  • Which type of film would typically require the least amount of input from a screenwriter?
    10·1 answer
  • I dont uderstand dis my teacher no helping pls help me i need to understand TEch
    10·1 answer
  • What is the extension of a Microsoft access database 2013​
    7·2 answers
  • Intelligent transportation systems use GPS to<br> Select all that apply.
    5·1 answer
  • A printer is considered to be in the category of
    5·2 answers
  • Cable inside the computer transferring data between the mother board and storage devices.
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!