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

  • Home
  • SEARCH
  • 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 8148355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:37:56+00:00 2026-06-06T14:37:56+00:00

Whenever I use permutations, I have to create a list of the permutations because

  • 0

Whenever I use permutations, I have to create a list of the permutations because it returns a ‘itertools.permutations object at 0x0190A5D0’. Then after I create the list, I have to combine the strings in each list so that I have the permutation I wanted originally. If it is a number, then I have to make them all integers again.

Two part question:

1) Is there an easier way to do a permutation and create the list of numbers?

2) Below I’ve created a permutation of a number with 5 digits. However, where I have ‘12345’, I want the user to input their own number. Thus the formatting string b=[‘s%s%s…] will have to be n %s and n x. Anyone know how to do this?

(FYI my program is trying to find the next largest number with the same digits given a user’s input so 12345 next largest is 12354)

Both questions were answered below please see both responses. Thanks!!!

def nexthighest():
    from itertools import permutations
    numb = str(12345)
    a = list(permutations(numb))
    b = ['%s%s%s%s%s' % xxxxx for xxxxx in a]  #<-- this is where the n length problem occurs
    c = list(map(int,b))
    for i in c:
        if i >12345:
            print(i)
            break
  • 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-06T14:37:56+00:00Added an answer on June 6, 2026 at 2:37 pm

    You don’t need to build all those lists. Just loop over the return value from permutations, joining and parsing as an integer each permutation as it comes by:

    def nexthigher(n):
        for p in permutations(sorted(str(n))):
            i = int("".join(p))
            if i > n:
                return i
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Whenever I use the SHA256.Create() method it always returns a null value. Here is
I have a problem with using the prefix, seems like whenever I use the
I have a FULLTEXT index called cart_product_fti on a table Whenever I use it,
I have problem with using dequeueReusableCellWithIdentifier method. Whenever I use this one, one cell
I have encountered a very strange issue. Whenever I use the .NET membership provider
Whenever I use the ORM deisgner in LinqToSql I have real problems trying to
Whenever I use ajax to dynamically create new content, .clone(), append() etc, the new
i have a gridview i wish to style without borders but whenever i use
Whenever I use the revert changes from this revision function in Tortoise SVN, then
How are integers and strings compared at a low level? Like whenever we use

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.