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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:07:15+00:00 2026-06-06T23:07:15+00:00

I have to create unique, unordered sets of 2 elements each from a list

  • 0

I have to create unique, unordered sets of 2 elements each from a list of numbers. Then insert each set into a list.

Eg:

  1. setslist = [(2,1)]
  2. uniquenumbers = [1,2,3]
  3. unique sets- (1,2),(2,3),(1,3)
  4. insert each set in setslist if it doesnt already exists. (Sets are unordered. So (1,2) is same as (2,1))
  5. Final setslist = [(2,1),(2,3),(1,3)]

What is the most optimized solution in python?

  • 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-06T23:07:17+00:00Added an answer on June 6, 2026 at 11:07 pm
    import itertools
    existing_sets = set(frozenset(x) for x in setslist)
    new_sets = set(frozenset(x) for x in itertools.combinations(uniquenumbers, 2))
    setslist = list(existing_sets | new_sets)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created the following method so as to create unique random numbers .
i have a table e.g: CREATE TABLE places (id UNIQUE, name, latitude, longitude) i
I have tried with ado.net create table columnName with unique name. as uniquename I
I have a template that creates a unique identifier for each type it is
I'd like to create a unique temporary directory in Windows from some C code
I have this string here: CREATE UNIQUE INDEX index555 ON SOME_TABLE ( SOME_PK ASC
I have a List of List<String> 's which I get from a external API
I have the following challenge that I need to create unique object tuples out
Should you always create unique keys whenever possible? For example let's say I have
I have the following unique contstraint defiend on a table: CREATE UNIQUE NONCLUSTERED INDEX

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.