python 华为od 单词接龙

复制代码
sd=['word','dd','da','dc','dword','d']
# 计算出下一个接龙单词
def jl(sd,st):
    # sd.remove(st)
    sd = list(set(sd))
    sends = list(st)[-1]
    lg = []
    sd.sort()
    for i in sd:
        if i.startswith(sends):
            lg.append((i, len(i)))
    if lg==[]:
        return 0,0
    lg.sort(key=lambda x: x[1],reverse=True)
    maxlen = lg[0][1]
    maxlenl = []
    for i in lg:
        if maxlen <= i[1]:
            maxlenl.append(i)
    if len(maxlenl) != 1:
        maxlenl.sort(key=lambda k: k[0])
    sd.remove(maxlenl[0][0])
    return maxlenl[0][0],sd

res=[]
res.append(sd[4])
ld=len(sd)
st=sd[4]
sd.remove(sd[4])
for i in range(0,ld):
    st,sd=jl(sd,st)
    if st:
        res.append(st)
    else:
        break
print(res)
相关推荐
sort浅忆9 小时前
deeptest执行接口脚本,添加python脚本断言
开发语言·python
冷月半明9 小时前
trea solo,让我从牛马外包翻身当“甲方”
python·trae
superman超哥9 小时前
仓颉借用检查器工作原理深度解析
c语言·开发语言·c++·python·仓颉
张彦峰ZYF10 小时前
Python 项目文件组织与工程化实践
python·项目文件组织与工程化实践
webbodys10 小时前
Python文件操作与异常处理:构建健壮的应用程序
java·服务器·python
MediaTea11 小时前
Python:实例 __dict__ 详解
java·linux·前端·数据库·python
SunnyDays101111 小时前
Python Excel 打印设置全攻略(打印区域、缩放、页边距、页眉页脚等)
python·excel打印设置·excel页面设置·excel打印选项
小鸡吃米…12 小时前
Python的人工智能-机器学习
人工智能·python·机器学习
傻啦嘿哟12 小时前
Python上下文管理器:优雅处理资源释放的魔法工具
开发语言·python
阿方索12 小时前
Python 基础简介
开发语言·python