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
How many answer or point do I answer/need to sent message?
Grace [21]

I'm a little confused about the question, but if you're asking how many points you need to ask a question, the minimum is 10.


4 0
3 years ago
1. image-editing software
Snezhnost [94]
  • PDF:-Portable Document Format
  • Database software:-software that organizes a collection of information
  • image-editing software :-software used to enhance photographs
  • presentation software :-software used to create a slide show
  • CAD:-software used to create technical drawings.

Done

8 0
2 years ago
You want to substitute one word with another throughout your
Hitman42 [59]
I’m pretty sure it’s “Find and paste”
8 0
3 years ago
What are the optional parameters when configuring DHCP
stealth61 [152]

Answer:

DHCP is the dynamic host configuration protocol that enable the server for assigning the IP address to the computer. It is basically used to provide automatic IP addresses within the network. It is basically used to configure the default gateway and provide the DNS server data in the device.  

The optional parameter when configuring DHCP are:

  • Sub-net mask
  • Router
  • Domain server
  • Broadcast address
  • Host name
5 0
3 years ago
If anyone plays pokemon go put your code below.
Cerrena [4.2K]
Yeah my pokémon is not my mom hung bye
4 0
2 years ago
Read 2 more answers
Other questions:
  • How can we set the color of a text that acts as a link in a web page​
    10·2 answers
  • When records are in ____ order, they are arranged one after another on the basis of the value in a particular field.?
    9·1 answer
  • Which view is used to allow a publisher to view facing pages of a publication at the same time? Normal Master Page Two-Page Spre
    5·1 answer
  • What social impact did the gunpowder have on society?
    12·1 answer
  • What is the problem with the code snippet below? public class Test { public static void main(String[] args) { System.out.println
    6·1 answer
  • Which command displays the contents of the NVRAM?
    13·1 answer
  • Flash drives, CDs, external disks are all examples of storage (memory) devices.'True or false?
    9·1 answer
  • The objective of this task is to use Scapy to estimate the distance, in terms of number of routers, between your VM and a select
    7·2 answers
  • Please please help I don’t understand this please.
    11·1 answer
  • BRIANLIEST!!!!!!!!!!!!!!!!
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!