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 6390375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:32:29+00:00 2026-05-25T03:32:29+00:00

I found this nice statement in a tutorial: for x,y in [(x,y) for x

  • 0

I found this nice statement in a tutorial:

    for x,y in [(x,y) for x in listA for y in listB]:

Now, as for me, I understood, that that statment will traverse listA and listB and x is a value of list A and y is a value from listB. But in this example the two lists had the same length. Will this statement also give me all pairs, if one list is longer than the other, or do I have to use a different statement?

Thanks in advance.

  • 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-05-25T03:32:29+00:00Added an answer on May 25, 2026 at 3:32 am

    The code computes the cartesian product (itertools.product), not zip as you suggested.

    For example, if the inputs are [1,2,3] and [4,5], the result is:

    (1,4)
    (1,5)
    (2,4)
    (2,5)
    (3,4)
    (3,5)
    

    For comparison, the result of zip([1,2,3], [4,5]) is:

    (1,4)
    (2,5)
    

    As you can see, zip (or itertools.izip) discards the additional items in the longer argument.

    Its variant itertools.izip_longest replaces these missing elements with an arbitrary value. For example, iterttools.izip_longest([1,2,3], [4,5], 99) returns:

    (1,4)
    (2,5)
    (3,99)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Following this nice example I found, I was trying to create a function that
I found this really nice function that receives your desired proportions and resizes/crops the
I want to make a nice, modern-looking transitions between pages. I've found this tutorial:
I just found out this nice SVN option that would be very useful on
I found this site/tutorial/demo from another question here on SO. Very nice and clean
I found this open-source library that I want to use in my Java application.
I found this nice snippet of code online: rkApp = Registry.LocalMachine.OpenSubKey(SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run, true); Which runs
I found this nice example of a Python C Module, where a single integer
I found a nice little script on snippr( http://snipplr.com/view.php?codeview&id=799 ) that gives me the
I found this nice example of doing paging in SQL Server, however, I need

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.