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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:53:36+00:00 2026-05-26T06:53:36+00:00

>>> import itertools >>> n = [1,2,3,4] >>> combObj = itertools.combinations(n,3) >>> >>> combObj

  • 0
>>> import itertools
>>> n = [1,2,3,4]
>>> combObj = itertools.combinations(n,3)
>>>
>>> combObj
<itertools.combinations object at 0x00000000028C91D8>
>>>
>>> list(combObj)
[(1, 2, 3), (1, 2, 4), (1, 3, 4), (2, 3, 4)]
>>>
>>> for i in list(combObj): #This prints nothing
...     print(i)
...
  1. How can i iterate through combObj ?

  2. How can i convert
    [(1, 2, 3), (1, 2, 4), (1, 3, 4), (2, 3, 4)]
    to
    [[1, 2, 3], [1, 2, 4], [1, 3, 4], [2, 3, 4]]

  • 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-26T06:53:37+00:00Added an answer on May 26, 2026 at 6:53 am

    Once you iterate through the itertools.combinations object once, it’s been used up and you can’t iterate over it a second time.

    If you need to reuse it, the proper way is to make it a list or tuple as you did. All you need to do is give it a name (assign it to a variable) so it sticks around.

    combList = list(combObject) # Don't iterate over it before you do this!
    

    If you want to iterate over it just once, you just don’t call list on it at all:

    for i in combObj: # Don't call `list` on it before you do this!
        print(i)
    

    Side note: The standard way to name object instances / normal variables would be comb_obj rather than combObj. See PEP-8 for more info.

    To convert the inner tuples to lists, use a list comprehension and the list() built-in:

    comb_list = [(1, 2, 3), (1, 2, 4), (1, 3, 4), (2, 3, 4)]
    comb_list = [list(item) for item in comb_list]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

import itertools print itertools#ok the code is ok but i can't find the itertools
To illustrate, I start with a list of 2-tuples: import itertools import operator raw
I took this script from here : import csv from itertools import izip f
I was doing a foolish thing like: from itertools import * rows = combinations(range(0,
I have two iterators, a list and an itertools.count object (i.e. an infinite value
Suppose I have this Python code: from itertools import count, tee original = count()
import itertools def _yield_sample(): it = iter(itertools.combinations('ABCD', 2)) it2 = iter(itertools.combinations('EFGH', 3)) itc =
I've generated the cartesian product of three dicts thus: import itertools combined = list(itertools.product(foo,
import java.lang.Math; public class NewtonIteration { public static void main(String[] args) { System.out.print(rootNofX(2,9)); }
import threading event = threading.Event() event.set() print event.wait(1) None event.clear() print event.wait(1) None So

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.