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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:41:16+00:00 2026-06-12T10:41:16+00:00

After performing some algorithm(s), I end up with a list similar to the one

  • 0

After performing some algorithm(s), I end up with a list similar to the one below:

l = Set([(integer_4_digits, integer_n_digits], ..)
ex: l = Set([(1011, 123556), (1041, 424553), (1241, 464096), (1027, 589325), (1011, 432341), (1031, 423076)])
l = list(l) #all tuples must exist once. need to get items by index to match (perhaps?)

Each tuple in this list has its first item a 4 digit integer (positive) and the second one, another positive integer.

What I want is:

To create a new list (of lists or tuples) where all the possible combinations are grouped together (in a list or a tuple) with cross matching, including a fifth (or 3rd, if it’s tuple+tuple+bool) element which is either True or False depending on whether or not if the first 4 digit integer of two newly matched-crossed tuples are the same or not (ex: 1011 == 1011 so Bool=True).

So after this process I want to get something like:

new_list = [(l[0], l[1], False), (l[0], l[2], False), (l[0], l[3], False), (l[0], l[4], True) ..
            (l[1], l[2], False), (l[1], l[3], False), (l[1], l[4], False), ..
            (l[2], l[3], False), (l[2], l[4], False), (l[2], l[5], False), ..]

As you can see, new_list does not contain duplicates matches. (l[0] is matched to l[1] only once, does not matter if the match tuple is a to be or b to a (l[0],l[1],..) or (l[1],l[0],..)

Now I can achieve this using nested for e in l loops and popping last e element and performing e[0] checks for bool and creating a new tuple (or list) and adding to the new_list list.

So how can I do this? How should I do it?

  • 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-12T10:41:17+00:00Added an answer on June 12, 2026 at 10:41 am

    Use itertools.combinations(); it creates the combinations you are looking for. Together with a list comprehension, you should be set:

    from itertools import combinations
    
    [(i, j, i[0] == j[0]) for i, j in combinations(l, 2)]
    

    Note that the Set type was made a built-in native type in python; just use set (lowercase) for the native version. We don’t need to turn the set into a list for this to work; itertools doesn’t care either way. You can even use the new {elem, elem, elem} set literal syntax.

    This produces:

    >>> from itertools import combinations
    >>> l = {(1011, 123556), (1041, 424553), (1241, 464096), (1027, 589325), (1011, 432341), (1031, 423076)}
    >>> [(i, j, i[0] == j[0]) for i, j in combinations(l, 2)]
    [((1041, 424553), (1027, 589325), False), ((1041, 424553), (1011, 123556), False), ((1041, 424553), (1031, 423076), False), ((1041, 424553), (1241, 464096), False), ((1041, 424553), (1011, 432341), False), ((1027, 589325), (1011, 123556), False), ((1027, 589325), (1031, 423076), False), ((1027, 589325), (1241, 464096), False), ((1027, 589325), (1011, 432341), False), ((1011, 123556), (1031, 423076), False), ((1011, 123556), (1241, 464096), False), ((1011, 123556), (1011, 432341), True), ((1031, 423076), (1241, 464096), False), ((1031, 423076), (1011, 432341), False), ((1241, 464096), (1011, 432341), False)]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After performing some operations I am getting a set of records. Example: a b
I am having a problem with precision of a double after performing some operations
After performing some tests I noticed that printf is much faster than cout .
After performing some Google-fu and searching Stack Overflow I've been unable to find a
I have written a GUI application which after performing some analyses on a large
I have a download page in php that after performing some checks returns a
I am creating a utility to insert few records into SQL after performing some
I want to show a specific ViewController (or dismiss) a View after performing an
I am having a problem where, after performing a simple mathematical operation on the
I am running a timer and performing a redirect after a user changes his

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.