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)
python 华为od 单词接龙
Stesthu2024-08-19 0:05
相关推荐
金銀銅鐵13 小时前
[Python] 从《千字文》中随机挑选汉字cup1118 小时前
[技术复盘] Windows Python 打包实战:Nuitka 环境踩坑总结与 CI 自动化构建全指南aqi0020 小时前
15天学会AI应用开发(七)有了大模型为什么还要引入RAG金銀銅鐵1 天前
用 Python 实现 Take-Away 游戏copyer_xyf1 天前
Agent 流程编排copyer_xyf1 天前
Agent RAGcopyer_xyf1 天前
【RAG】向量数据库:milvuscopyer_xyf1 天前
Agent 记忆管理星云穿梭2 天前
用Python写一个带图形界面的学生管理系统——完整教程