Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8187221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:29:23+00:00 2026-06-07T02:29:23+00:00

I have two lists a = [1,2,3] b = [9,10] I want to combine

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T02:29:25+00:00Added an answer on June 7, 2026 at 2:29 am

    Normally, you use itertools.zip_longest for this:

    >>> import itertools
    >>> a = [1, 2, 3]
    >>> b = [9, 10]
    >>> for i in itertools.zip_longest(a, b): print(i)
    ... 
    (1, 9)
    (2, 10)
    (3, None)
    

    But zip_longest pads the shorter iterable with Nones (or whatever value you pass as the fillvalue= parameter). If that’s not what you want then you can use a comprehension to filter out the Nones:

    >>> for i in (tuple(p for p in pair if p is not None) 
    ...           for pair in itertools.zip_longest(a, b)):
    ...     print(i)
    ... 
    (1, 9)
    (2, 10)
    (3,)
    

    but note that if either of the iterables has None values, this will filter them out too. If you don’t want that, define your own object for fillvalue= and filter that instead of None:

    sentinel = object()
    
    def zip_longest_no_fill(a, b):
        for i in itertools.zip_longest(a, b, fillvalue=sentinel):
            yield tuple(x for x in i if x is not sentinel)
    
    list(zip_longest_no_fill(a, b))  # [(1, 9), (2, 10), (3,)]
    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two List<int> instances. Now I want to combine them into a third
I have a function that cycles through two sperate lists and combines them into
I have two lists that i need to combine where the second list has
I simply want to remove duplicates from two lists and combine them into one
Specifically, I have two lists of strings that I'd like to combine into a
I have two lists List that I need to combine in third list and
I have two employee lists that I want to get only unique records from
If I have two generic lists, List, and I want to merge all the
Ho I have two list view on a frame layout. I want one overlay
I have two lists with data that I want to compare dates for. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.