subject

Implement the function permutations() that takes a list lst as input and returns a list of all permutations of lst (so the returned value is a list of lists). Do this recursively as follows: If the input list lst is of size 1 or 0, just return a list containing list lst. Otherwise, make a recursive call on the sublist l[1:] to obtain the list of all permutations of all elements of lst except the first element l[0]. Then, for each such permutation (i. e., list) perm, generate permutations of lst by inserting lst[0] into all possible positions of perm. >>> permutations([1, 2])

[[1, 2], [2, 1]]

>>> permutations([1, 2, 3])

[[1, 2, 3], [2, 1, 3], [2, 3, 1], [1, 3, 2], [3, 1, 2], [3, 2, 1]]

>>> permutations([1, 2, 3, 4])

[[1, 2, 3, 4], [2, 1, 3, 4], [2, 3, 1, 4], [2, 3, 4, 1],

[1, 3, 2, 4], [3, 1, 2, 4], [3, 2, 1, 4], [3, 2, 4, 1],

[1, 3, 4, 2], [3, 1, 4, 2], [3, 4, 1, 2], [3, 4, 2, 1],

[1, 2, 4, 3], [2, 1, 4, 3], [2, 4, 1, 3], [2, 4, 3, 1],

[1, 4, 2, 3], [4, 1, 2, 3], [4, 2, 1, 3], [4, 2, 3, 1],

[1, 4, 3, 2], [4, 1, 3, 2], [4, 3, 1, 2], [4, 3, 2, 1]]

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 12:00
Which of these is an example of an integrated presentation? a. a table created in powerpoint b. an image pasted into powerpoint c. a caption created in powerpoint d. an excel chart pasted into powerpoint
Answers: 1
question
Computers and Technology, 23.06.2019 12:40
Curriculum exam to process a resident's payment, you must click on onesite payments home page. from the a. reports b. my settings o c.transactions o d. rent tab
Answers: 1
question
Computers and Technology, 23.06.2019 14:30
Select the correct answer. a company wants to use online methods to target more customers. it decides to conduct a market research by collecting the data of a few customers with their consent. they want to track data of the sites that their customers frequently visit. which software can the company? a. spyware b. bots c. adware d. trojan horse e. rootkits
Answers: 1
question
Computers and Technology, 23.06.2019 22:20
If i uninstall nba 2k 19 from my ps4 will my career be gone forever?
Answers: 2
You know the right answer?
Implement the function permutations() that takes a list lst as input and returns a list of all permu...
Questions
question
Business, 08.07.2019 09:00
question
Biology, 08.07.2019 09:00
question
History, 08.07.2019 09:00
question
Mathematics, 08.07.2019 09:00
question
History, 08.07.2019 09:00
Questions on the website: 13722363