本帖最后由 沉默的人e 于 2020-7-19 15:15 编辑
python简单题 第四期 (争取月更)
(你就不会弄一个统一的标题吗!!!)
前几期的题目过于简单(过于简单...)
为了让我的题目值那些鱼币,所以,简单题要略微增加难度.
(不过还是相信鱼油能做出来,毕竟是一个大一的学生,再难能难到哪里去)
不废话,上题:
Given a set of data composed of numbers, the permutation of the set of data needs to be output. Each arrangement method needs to be packed with [], and the result of the overall arrangement will be packed with [].
For example, to output the permutation of [1,3], your result should be [[1,3],[3,1]]
It is not allowed to use built-in functions or import modules to complete this operation directly.
For example, if there is a module named a.py whose function b can return the permutation of data, the following statements are prohibited:hints: the dataset which will be permutated should be gotten by using the input() function
这是力扣网上的题目,经过了简单的修改,呈现出来. 题目不难,真的不难! 以函数式编程方式书写程序 最先给出答案,并且答案最简洁单纯的为最佳答案. 本系列虽鱼币有所缩减但仍然不少,请大家加油,最佳答案者,获得 25 鱼币哦
def func(l):
rets = []
def fun2(chs, sz=[]):
if not chs:
rets.append(sz)
for c in chs:
szc = sz.copy()
chsc = chs.copy()
szc.append(c)
chsc.remove(c)
fun2(chsc, szc)
fun2(l)
return rets
|