Hw05 题解 (UCB CS61A@2021 Fall)
Q1: Generate Permutations
Given a sequence of unique elements, a permutation of the sequence is a list containing the elements of the sequence in some arbitrary order. For example,
[2, 1, 3],[1, 3, 2], and[3, 2, 1]are some of the permutations of the sequence[1, 2, 3].Implement
gen_perms, a generator function that takes in a sequenceseqand returns a generator that yields all permutations ofseq. For this question, assume thatseqwill not be empty.