Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Adhere to style in PEP 8 Contain docstrings explaining purposes Outline has been given below from __future__ import annotations def perm_gen_lex(string: str) -> list[str]: pass

image text in transcribed

Adhere to style in PEP 8

Contain docstrings explaining purposes

Outline has been given below

from __future__ import annotations

def perm_gen_lex(string: str) -> list[str]:

pass # TODO: implement me and remove this line of code

1 Permutations in Lexicographic Order 1.1 Specification We are going to write a Python program to generate all the permutations of the characters in a string. This will give you a chance to review some Python constructs (e.g. strings and lists) and also solidify your understanding of recursion. Your program must meet the following specifications. In a file named perm_lex.py, You are to write a Python function perm_gen_lex that: - Takes a string as a single input argument. You may assume that the input string will be 0 or more unique lower-case letters in alphabetical order. - Returns a Python list of strings where each string represents a permutation of the input string. The list of permutations must be in lexicographic (i.e. dictionary) order. Note: if you follow the pseudocode below, your list will be constructed such that this condition will be met. Do not sort the list. - Is recursive and follows the pseudocode in Section 1.3. 1.2 Examples As an example of what this function does: Note: For a string with n characters, your program will return a list containing n! strings. This will grow very quickly. If your string contained every lowercase letter a to z ( 26 letters), the resulting list of permutations would have 403,291,461,126,605,635,584,000,0004.031026 elements. If you want your code to finish in your lifetime, you should probably stick to shorter strings for testing. 1.3 Pseudocode You must follow this pseudocode! Note, my simple pseudocode never mentions a base case. Your code will need one to function correctly. Think about what it should be and what you should return in that case. My pseudocode also uses bad variable names (semi-intentionally). I expect better from your code. \begin{tabular}{l} \hline perm_gen_lex (s) \\ Input: A string s \\ Output: A list of all permutations of the characters in s in lexicographic order \\ for each character c in s do \\ Form a simpler string, t, by removing c from s \\ Generate all permutations of t recursively \# ie. call perm_gen_lex (t) \\ for each permutation p of t do \\ Add c to the front of p and add the result to your list of permutations \\ return the list of permutations \end{tabular}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

List the different categories of international employees. page 642

Answered: 1 week ago

Question

Explain the legal environments impact on labor relations. page 590

Answered: 1 week ago