python merge two lists (even/odd elements)

后端 未结 7 1325
旧时难觅i
旧时难觅i 2021-01-19 16:16

Given two lists, I want to merge them so that all elements from the first list are even-indexed (preserving their order) and all elements from second list are odd-indexed (a

相关标签:
7条回答
  • 2021-01-19 17:00

    If you have same length lists, you can use this:

    result = [ item for tup in zip(x,y) for item in tup ]
    
    0 讨论(0)
提交回复
热议问题