I have two lists:
[a, b, c] [d, e, f]
I want:
[a, d, b, e, c, f]
What’s a simple way to do this in Python?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
One option is to use a combination of
chain.from_iterable()andzip():Edit: As pointed out by sr2222 in the comments, this does not work
well if the lists have different lengths. In that case, depending on
the desired semantics, you might want to use the (far more general)
roundrobin()function from the recipe
section of the
itertoolsdocumentation: