-3

How can I merge the two lists in one by selecting 1st element from 1st list 2nd element from second list 2nd element...and then 3rd element from 1st list 3rd element
list 1=[a,b,c,d,e,f,] and
list 2=[g,h,i,j,k,l]
the required list is
list 3=[a,h,c,j,e,l]
in Python

I tried slicing with two loop it doesn't work for me

halfer
  • 19,824
  • 17
  • 99
  • 186
  • Welcome to SO. Please read [Under what circumstances may I add "urgent" or other similar phrases to my question, in order to obtain faster answers?](//meta.stackoverflow.com/q/326569) – Mike Scotty Feb 23 '23 at 12:54
  • Welcome to SO. First of all, please take your time to follow the [tour] and read how to ask good questions, as you should always try to provide enough details, and consider that it's usually good practice to provide a [MRE]. – Malo Feb 23 '23 at 13:00
  • There are fundamentally two ways to approach the problem: we can iterate through the lists in parallel (first duplicate), so that we consider each pair of values (a vs g, b vs h, etc), and use some logic to choose the right one each time through the loop. Or we can take the appropriate slices of the lists (a, c, e and h, j, l) like the third duplicate, and interlace them like in the second duplicate. – Karl Knechtel Feb 23 '23 at 13:14

1 Answers1

-1
list3 = []
for i in range(0,len(list1),2):
    list3.append(list1[i])
    list3.append(list2[i+1])
Ugur Yigit
  • 155
  • 7