I have two lists
a = [1,2,3]
b = [9,10]
I want to combine (zip) these two lists into one list c such that
c = [(1,9), (2,10), (3, )]
Is there any function in standard library in Python to do this?
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.
Normally, you use
itertools.zip_longestfor this:But
zip_longestpads the shorter iterable withNones (or whatever value you pass as thefillvalue=parameter). If that’s not what you want then you can use a comprehension to filter out theNones:but note that if either of the iterables has
Nonevalues, this will filter them out too. If you don’t want that, define your own object forfillvalue=and filter that instead ofNone: