如何在python中交错两个列表?

时间:2016-08-02 22:17:49

标签: python

我有2个python列表:

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

我想将这两个列表交错到c_list,以便c_list看起来像这样:

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

如何做到最好?

1 个答案:

答案 0 :(得分: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)