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)
相关推荐
databook3 小时前
探索视觉的边界:用 Manim 重现有趣的知觉错觉
python·动效
明月_清风4 小时前
Python 性能微观世界:列表推导式 vs for 循环
后端·python
明月_清风4 小时前
Python 性能翻身仗:从 O(n) 到 O(1) 的工程实践
后端·python
helloweilei20 小时前
python 抽象基类
python
用户83562907805120 小时前
Python 实现 PPT 转 HTML
后端·python
zone77391 天前
004:RAG 入门-LangChain读取PDF
后端·python·面试
zone77391 天前
005:RAG 入门-LangChain读取表格数据
后端·python·agent
树獭非懒2 天前
AI大模型小白手册|Embedding 与向量数据库
后端·python·llm
唐叔在学习2 天前
就算没有服务器,我照样能够同步数据
后端·python·程序员
曲幽2 天前
FastAPI流式输出实战与避坑指南:让AI像人一样“边想边说”
python·ai·fastapi·web·stream·chat·async·generator·ollama