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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:07:20+00:00 2026-05-31T18:07:20+00:00

Is there any smart way to write a list comprehension over more than one

  • 0

Is there any smart way to write a list comprehension over more than one list?

I know I could use a separate range list as index but this way I have to know the length (or get it separately with a len() function call).

>>> a = range(10)
>>> b = range(10, 0, -1)
>>> [(a[x],b[x]) for x in range(10)]
[(0, 10), (1, 9), (2, 8), (3, 7), (4, 6), (5, 5), (6, 4), (7, 3), (8, 2), (9, 1)]

I’d love to have something like this:

>>> [(a,b) for a in range(10) and b in range(10, 0, -1)]
[(0, 10), (1, 9), (2, 8), (3, 7), (4, 6), (5, 5), (6, 4), (7, 3), (8, 2), (9, 1)]

How would you write the list comprehension? Is there a way to do this with itertools?

The range list just stand for any list and I do not necessarily want to get a tuple. there could also be a function which takes a and b as parameters. So zip is not what I want.

UPDATE: With “So zip is not what I want.” I meant that I don’t want zip(range(10), range(10, 0, -1))

  • 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-31T18:07:21+00:00Added an answer on May 31, 2026 at 6:07 pm

    Your example is just:

    zip(range(10), range(10, 0, -1))
    

    More generally, you can join any set of iterables using zip:

    [func(a, d, ...) for a, b, ..., n in zip(iterable1, iterable2, ..., iterableN)]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any smart way to do this? If using Linq2Nhibernate , you really
Is there any way using log4net to automatically write date/time and class name/function name
Is there any way to start foobar.js WSH-script in order that standard Task Manager
Is there any way to control and manual specification for start of teaser ?.
Is there any way to set the directory where you want to start a
If I am walking through an IEnumerable<T> , is there any way to get
I'm wondering if there's a way to write-protect every page in a Linux process'
I'm attempting to use the ReaderWriterLockSlim class to manage a list. There are many
Is there a way to add the output of sys.stdout.write to a variable? Or
I was wondering if there was any (legal) way to track websites analytics of

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.