Pythonic way to combine two lists in an alternating fashion?

前端 未结 21 3285
误落风尘
误落风尘 2020-11-22 16:13

I have two lists, the first of which is guaranteed to contain exactly one more item than the second. I would like to know the most Pythonic way to create a

21条回答
  •  执笔经年
    2020-11-22 17:01

    I'd do the simple:

    chain.from_iterable( izip( list1, list2 ) )
    

    It'll come up with an iterator without creating any additional storage needs.

提交回复
热议问题