鱼C论坛

 找回密码
 立即注册
查看: 1927|回复: 6

[已解决]Python简单题第四期

[复制链接]
发表于 2020-7-18 11:44:36 | 显示全部楼层 |阅读模式
25鱼币
本帖最后由 沉默的人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:
import a
a.b([1,3])
hints: the dataset which will be permutated should be gotten by using the input() function

这是力扣网上的题目,经过了简单的修改,呈现出来.
题目不难,真的不难!
以函数式编程方式书写程序
最先给出答案,并且答案最简洁单纯的为最佳答案.
本系列虽鱼币有所缩减但仍然不少,请大家加油,最佳答案者,获得
25
鱼币哦


最佳答案
2020-7-18 11:44:37
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

本帖被以下淘专辑推荐:

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2020-7-18 11:44:37 | 显示全部楼层    本楼为最佳答案   
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
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2020-7-18 14:27:08 | 显示全部楼层
这里有字符串型的,先凑合着,待会儿给完整版
f = lambda chs, sz: print(sz) if chs == '' else [f(chs.replace(c, ''), sz + c) for c in chs]
f("FishC", '')
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2020-7-18 18:05:31 | 显示全部楼层
实现全排列,你管这叫简单题?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2020-7-18 23:30:28 | 显示全部楼层
突然觉得当年我要是把我每月的大作业都按时po在论坛上是不是就能坐等答案了.......
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2020-7-19 15:17:00 | 显示全部楼层
呃,忘了说时限了.

时限到8月10号之前.

八月十号当天我会选出最佳答案者
各位加油哦!


想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2020-7-22 13:42:01 | 显示全部楼层
谁能翻译一下题目
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-6-16 18:32

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表