Question

In: Computer Science

in python how would create permuntations of a list with digits 0-9 using recursion with at...

in python how would create permuntations of a list with digits 0-9 using recursion with at most two for loops and no other lib allowed?

needs to return all perm length between 3-7 if possbile

Solutions

Expert Solution

def permutations(digits):

        def permutationsHelper(digits):
                if len(digits) == 1:
                        return [str(digits[0])]
                c = str(digits[0])
                perms = permutationsHelper(digits[1:])
                
                result = []
                for p in perms:
                        for i in range(len(p) + 1):
                                x = p[:i] + c + p[i:]
                                result.append(x)

                return result + perms

        result = permutationsHelper(digits)
        result = [x for x in result if 3 <= len(x) <= 7]
        return result

print(permutations([0, 1, 2, 5, 4]))
**************************************************

Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.

Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.


Related Solutions

In python I want to create a function that takes in a linked list. Using recursion...
In python I want to create a function that takes in a linked list. Using recursion only, I want to check if the linked list is sorted. How do i do this?
Write a program in python that implements quicksort, first using recursion and then without recursion.
Write a program in python that implements quicksort, first using recursion and then without recursion.
Python: How would I write a function using list comprehensions to list of integers into two...
Python: How would I write a function using list comprehensions to list of integers into two halves with the evens first, followed by odds? And on top of that, the numbers should be listed in their original order.
In python write a program that first creates a list with the integers 0 through 9...
In python write a program that first creates a list with the integers 0 through 9 and then traverses that list RECURSIVELY (no for/while loops allowed) and prints out the integers on the list. NOTE: creating the list does not have to be done recursively.
1a. An ATM requires a four-digit PIN, using the digits 0-9. How many PINs have no...
1a. An ATM requires a four-digit PIN, using the digits 0-9. How many PINs have no repeated digits? 1b. How many ways can president and vice president be determined in a club with twelve members? 1c. A security team visits 12 offices each night. How many different ways can the team order its visits? 1d. In a certain lottery you select seven distinct numbers from 1 through 39, where order makes no difference. How many different ways can you make...
USING PYTHON Write a program to create a number list. It will call a function to...
USING PYTHON Write a program to create a number list. It will call a function to calculate the average values in the list. Define main ():                        Declare variables and initialize them                        Create a list containing numbers (int/float)                        Call get_avg function that will return the calculated average values in the list.                                       Use a for loop to loop through the values in the list and calculate avg                        End main()
How to do this in Python (using Lists): Create a python program that allows a user...
How to do this in Python (using Lists): Create a python program that allows a user to display, sort and update as needed a List of U.S States containing the State Capital and State Bird. You will need to embed the State data into your Python code. The user interface will allow the user to perform the following functions: 1. Display all U.S. States in Alphabetical order along with Capital and Bird 2. Search for a specific state and display...
How to create a FTP server using python and TCP Ports How to create a FTP...
How to create a FTP server using python and TCP Ports How to create a FTP server using python and UDP Ports
Using Python, use the following list (Temperature = [56.2,31.8,81.7,45.6,71.3,62.9,59.0,92.5,95.0,19.2,15.0]) to: - Create a loop to iterate...
Using Python, use the following list (Temperature = [56.2,31.8,81.7,45.6,71.3,62.9,59.0,92.5,95.0,19.2,15.0]) to: - Create a loop to iterate through each of the elements in the temperature list. - Convert each element of this list to a Celsius temperature and then, for each valid temperature in the list, print out both the original Fahrenheit temperature and the Celsius equivalent in this format: "32 degrees Fahrenheit is equivalent with 0 degrees Celsius."
For 3 digits password. a). Find all possible outcomes of 3 digits of 0-9 numbers with...
For 3 digits password. a). Find all possible outcomes of 3 digits of 0-9 numbers with no repetition allowed b). Find all possible outcomes of 3 digits of 0-9 numbers with repeition allowed but no more than two repetition c). Find all possible outcomes of 3 digits of 0-9 for repetition numbers only. d) Find all possible outcomes of 3 digits of 0-9 for repeition numbers only but no more than 2 repetition. e). Find all possible outcomes of 3...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT