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
相关推荐
月光船幽幽16 分钟前
检测用户意图复杂性的关键方法威联通网络存储3 小时前
TS-h3087XU-RP 汽车零部件质检追溯部署你驴我3 小时前
WhatsApp 多账号场景下的会话归档与历史消息检索优化实践IT毕设实战小研4 小时前
基于安卓的空气质量查询系统harmful_sheep4 小时前
java group by常见用法whcyhhh5 小时前
头歌实践教学平台:数据科学与大数据技术导论(十六)宸津-代码粉碎机5 小时前
AI工程化高阶实战|从Demo到生产落地核心架构、全套源码与避坑指南郝学胜-神的一滴6 小时前
Effective Python 条款4:字符串格式化大乱斗ynchyong6 小时前
Python 字符组合生成器:product 与 permutations 的实战对比benchmark_cc6 小时前
1000只ETF的5分钟K线如何批量获取?QuantDash分页策略与高性能Python实践