-2

I have 2 python lists:

>>> a_list = [1, 2, 3]
>>> b_list = ["a", "b"]

I want to interleave these two lists together into c_list such that c_list looks likes this:

[1, "a", 2, "b", 3]

How best to do it??

Saqib Ali
  • 11,931
  • 41
  • 133
  • 272
  • 1
    See the ```roundrobin``` function in the [itertools recipes](https://docs.python.org/3/library/itertools.html#itertools-recipes) in thd docs. – wwii Aug 02 '16 at 22:32

1 Answers1

0
result = []
while a_list and b_list:
  result.append(a_list.pop(0))
  result.append(b_list.pop(0))
result.extend(a_list)
result.extend(b_list)
Dan
  • 1,874
  • 1
  • 16
  • 21