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)
相关推荐
Warson_L1 小时前
高性能架构设计
python·go
databook2 小时前
新数据到手,先跑哪几步检查
python·数据分析
czq_26867194873 小时前
Python打卡第46天
开发语言·python
Flynt4 小时前
日涨4000星的OSINT工具,我拿Linus的用户名和一个随机字符串实测了一遍
python·安全
曲径海盗6 小时前
【Python 学习第 53 天】列表基础
python·学习笔记·编程入门
Dumbness6 小时前
群里 @ 机器人发"查订单",指令一条都没命中:微信群机器人在路由前漏掉的几步归一化
python·微信
用户1614840955457 小时前
用 M4 Pro 跑羽毛球视频 AI 分析(二):TrackNet MPS 加速 3.2 倍、卡尔曼滤波补漏与自动回合剪辑
python
用户4019925568617 小时前
基于对话树回溯的社媒评论流买方意图识别与噪音过滤实践
python
用户0332126663677 小时前
使用 Python 加密或解密 PDF 文档
python
小七-七牛开发者8 小时前
让 Go 走得更远:用 LLGo 打通 Go 与 C/C++/Python 生态
python·编程·编译器·llvm·llgo