这个单词接龙怎么写
下面这个是自己写了一点没写完的
from random import *
m=int(input("单词数量:"))
start=eval(input("开头的字母:"))
def wordgo(n,start):
n=[lbk]word for word in ls if word.startswith(start)[rbk]
n.sorted(key=len,reverse=True)
def dfs(index,currentw):
if index==len(n):
return currentw
longest=""
for i in range(index,len(n)):
if not any(word in currntw or currentw in word for word in n[lbk]index:[rbk]):
nextw=word[lbk]i[rbk]
result=dfs(i+1,currentw+nextw[lbk]len(currentw):[rbk])
if len(result)>len(longest):
longest=result
return=longest
return dfs(0,"")
file=open("words.txt",'r')
n=file.readlines()
下面这个是自己写了一点没写完的
from random import *
m=int(input("单词数量:"))
start=eval(input("开头的字母:"))
def wordgo(n,start):
n=[lbk]word for word in ls if word.startswith(start)[rbk]
n.sorted(key=len,reverse=True)
def dfs(index,currentw):
if index==len(n):
return currentw
longest=""
for i in range(index,len(n)):
if not any(word in currntw or currentw in word for word in n[lbk]index:[rbk]):
nextw=word[lbk]i[rbk]
result=dfs(i+1,currentw+nextw[lbk]len(currentw):[rbk])
if len(result)>len(longest):
longest=result
return=longest
return dfs(0,"")
file=open("words.txt",'r')
n=file.readlines()