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)
相关推荐
Petrichor_H_1 天前
DAY 31 文件的规范拆分和写法
python
咚咚王者1 天前
人工智能之编程进阶 Python高级:第九章 爬虫类模块
开发语言·python
深蓝海拓1 天前
使matplot显示支持中文和负号
开发语言·python
AntBlack1 天前
AI Agent : CrewAI 简单使用 + 尝试一下股票分析
后端·python·ai编程
一眼万里*e1 天前
搭建本地deepseek大模型
python
1***Q7841 天前
PyTorch图像分割实战,U-Net模型训练与部署
人工智能·pytorch·python
二进制的Liao1 天前
【编程】脚本编写入门:从零到一的自动化之旅
数据库·python·算法·自动化·bash
Dxy12393102161 天前
Python为什么要使用可迭代对象
开发语言·python
Keep_Trying_Go1 天前
论文STEERER人群计数,车辆计数以及农作物计数算法详解(pytorch)
人工智能·pytorch·python
gzu_011 天前
基于昇腾 配置pytorch环境
人工智能·pytorch·python