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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:49:58+00:00 2026-06-04T05:49:58+00:00

I have found several answers to this problem, however it is not what i

  • 0

I have found several answers to this problem, however it is not what i intended to do.

When I have a list:

[1,2,3],[4,5,6],[7,8,9]

And I would like to have all possible combinations:

[1,2,3],[7,8,9],[4,5,6]
[1,2,3],[4,5,6],[7,8,9]
[7,8,9],[4,5,6],[1,2,3]
....

But is there an easy solution for this in python?

Thanks, and is it also possible to create 1 list instead of 3 like:
[7,8,9,4,5,6,1,2,3]

  • 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-04T05:49:59+00:00Added an answer on June 4, 2026 at 5:49 am

    itertools.permutations is what you’re looking for I think.

    >>> import itertools
    >>> l = [1,2,3],[4,5,6],[7,8,9]
    >>> list(itertools.permutations(l, len(l)))
    [([1, 2, 3], [4, 5, 6], [7, 8, 9]), 
      ([1, 2, 3], [7, 8, 9], [4, 5, 6]),
      ([4, 5, 6], [1, 2, 3], [7, 8, 9]), 
      ([4, 5, 6], [7, 8, 9], [1, 2, 3]),
      ([7, 8, 9], [1, 2, 3], [4, 5, 6]),
      ([7, 8, 9], [4, 5, 6], [1, 2, 3])]
    

    And merged together:

    >>> [list(itertools.chain(*x)) for x in itertools.permutations(l, len(l))]
    
    [[1, 2, 3, 4, 5, 6, 7, 8, 9], 
    [1, 2, 3, 7, 8, 9, 4, 5, 6], 
    [4, 5, 6, 1, 2, 3, 7, 8, 9], 
    [4, 5, 6, 7, 8, 9, 1, 2, 3], 
    [7, 8, 9, 1, 2, 3, 4, 5, 6],
    [7, 8, 9, 4, 5, 6, 1, 2, 3]]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have found several similar answers but I can't quite get why this is
I've investigated several C# DLL's and have not found any that work especially well.
I have found the way to copy the record that I would like, but
I have found several questions and answers pertaining to my question, but I'm getting
I have an NSMutableArray which can hold several objects. I would like to check
First post, have found many answers here, so hopes are high. The problem: Google
I have found several other questions here on S.O. (and the web in general)
I have found several guides on how to get a 3D animation to flip
I have found several questions asking about template typedefs in C++0x, which are resolved
I have found several examples using datamapper and was able to get them to

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.