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.
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...
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.
Solving Problems Using Recursion (Python): To solve the problem, you have to use recursion and cannot...
Solving Problems Using Recursion (Python): To solve the problem, you have to use recursion and cannot use for or while loops to solve the problems as well as not using global variables. 1. Create a function that takes a positive integer and returns it with neighboring digits removed. Do not convert the integer to a list. Ex. Input = [5555537777721] Output = [53721]
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()
Using python Create a function that inputs a list of numbers and outputs the median of...
Using python Create a function that inputs a list of numbers and outputs the median of the numbers. sort them and them show the output.
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...
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
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT