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)
相关推荐
Wyz201210243 分钟前
SQL中如何处理GROUP BY的不可排序问题_ORDERBY与聚合
jvm·数据库·python
Java面试题总结5 分钟前
Python 入门(四)- Openpyxl 操作 Excel 教程
开发语言·python·excel
Polar__Star9 分钟前
jsoup如何读取html
jvm·数据库·python
smj2302_7968265210 分钟前
解决leetcode第3901题好子序列查询
python·算法·leetcode
a95114164212 分钟前
怎么防范通过phpMyAdmin上传WebShell_禁止into outfile权限
jvm·数据库·python
2401_8858850413 分钟前
群发彩信接口怎么开发?企业级彩信发送说明
前端·python
InfinteJustice14 分钟前
如何统计SQL分组汇总数据_详解GROUP BY与HAVING用法
jvm·数据库·python
Freak嵌入式14 分钟前
aiohttps异步HTTPS库:uPyPI+MicroPython一键安装
人工智能·python·网络协议·http·https·micropython
PILIPALAPENG14 分钟前
第2周 Day 5:前端转型AI开发,朋友问我,你到底在折腾啥?
前端·人工智能·python
zhangchaoxies15 分钟前
如何使用 AWS Lambda 和 Python 获取 EMR 集群的标签列表
jvm·数据库·python