【问题标题】:Python: joining two lists [duplicate]Python:加入两个列表[重复]
【发布时间】:2015-05-09 05:46:04
【问题描述】:

如何通过交替取元素来组合两个列表。例如:给定两个列表 ['a','b','c'] 和 [1, 2, 3, 4],函数应该返回 [a, 1, b, 2, c, 3, 4]

【问题讨论】:

    标签: python list python-2.7


    【解决方案1】:
    a = [1, 2, 3, 4]
    b = ['a','b','c'] 
    
    result = [item for sublist in zip(b,a) for item in sublist]
    
    print result
    

    【讨论】:

    • zip(a,b) 换成zip(b,a)
    猜你喜欢
    • 2022-12-24
    • 2014-10-08
    • 2021-04-25
    • 2012-04-27
    • 1970-01-01
    • 1970-01-01
    • 2013-01-26
    • 2020-11-05
    • 1970-01-01
    相关资源
    最近更新 更多