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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T11:15:38+00:00 2026-06-02T11:15:38+00:00

The itertools function has no error but it also doesn’t print anything once its

  • 0

The itertools function has no error but it also doesn’t print anything once its complete.
My code is:

def comb(iterable, r):
    pool = tuple(iterable)
    n = len(pool)
    for indices in permutations(range(n), r):
        if sorted(indices) == list(indices):
            print (indices)
            yield tuple(pool[i] for i in indices)

I included the print statement but it doesn’t print the total combinations it calculated.

  • 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-02T11:15:40+00:00Added an answer on June 2, 2026 at 11:15 am

    You need to read up on how generators work. When you call comb() it returns a generator object. You need to then do something with the generator object to get the objects returned from it.

    from itertools import permutations
    
    lst = range(4)
    result = list(comb(lst, 2))  # output of print statement is now shown
    
    print(result) # prints: [(0, 1), (0, 2), (0, 3), (1, 2), (1, 3), (2, 3)]
    

    comb() returns a generator object. Then, list() iterates it and collects the values in a list. At the time of iteration, your print statement fires.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use the itertools module to use the permutations function but I'm
Not sure how to look around for this, but from itertools the function izip_longest
I need a function that functions in a similar manner as itertools.product, but without
I have a function that has a dictionary as input and a value n.
I need to compute combinatorials (nCr) in Python but cannot find the function to
I was trying to implement the reverse function of itertools.izip on Python 2.7.1. The
I keep thinking there should be a function for this, but I've searched the
I'm creating a generator that gets consumed by another function, but I'd still like
Suppose I have this Python code: from itertools import count, tee original = count()
I noticed that itertools does not (it seems to me) have a function capable

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.