search

Home  >  Q&A  >  body text

Python如何优雅的交错合并两个列表

比如a = [1, 2, 3], b = [4, 5, 6]
合并为[1, 4, 2, 5, 3, 6]
你觉得怎么写比较优雅?

伊谢尔伦伊谢尔伦2806 days ago1136

reply all(11)I'll reply

  • 大家讲道理

    大家讲道理2017-04-17 14:30:20

    a = [1,2,3]
    b = [4,5,6]
    s = []
    for i in zip(a,b):s.extend(list(i))
    print s

    result:

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

    reply
    0
  • Cancelreply