[英]python small crosswords for beginners
my_str="ellezagchickenbndodetballigatoraaaolmeznacattleeblrctacfenarcesssadlritfhftrarrssos aoiarefaareppohssarghcerumrheirmmwildfcumeboimltaairfovindalbiglalobehoeasiaxuesabldinbbccrhhrtylrlahsifdlogkrctlaiareogoldfinchefnnddmneepoletnarntadodinosauroxofoeclictnahpelepalgaierhohcaorkcocyatrmoacrflamingoerefafloechateehchdracaribou"
def create_2d_list(N):
output_list=[]
counter=0
for row in range(0,N):
temp=[]
for col in range(0,N):
temp.append(my_str[counter])#you can add a charcter instead of counter
counter=counter+1
output_list.append(temp[:])
return output_list
N=18
x=create_2d_list(N)
for row in range(0,N):
total=0
s="|"
for col in range(0,N):
my_str="{0:2} ".format(x[row][col])
s=s+my_str+"|"
print "-"*(N*4+1)
print s,
print " "
the_valid_words=open("E:/asd/words.txt","r").readlines()
def looking_word_left_to_right(the_list):
for any_words in the_valid_words:
for every in x[0]:
the_first_index=x[0].index(every)
for every in range(the_first_index,(the_first_index)+7):
c=str(every)
the_join=" ".join(c)
if the_join==the_valid_words:
word.upper().replace(every,x[0].upper(every))
return x[0]
print looking_word_left_to_right(x)
每次我运行程序时,looking_word_left_to_right都不会打印任何内容
PS:对于初学者来说,它类似于小填字游戏,如果有人可以对如何继续进行思考,那将是一个不错的选择。 我有一些有效的单词要寻找。
而且我是新手,所以请放轻松:)感谢您的帮助。
似乎有很多问题。
x
时,你也把它作为the_list"
只要使用the_list
。 x
的第一行,并且永远不会超越它。 " ".join(c)
将为您提供"abcdefg"
。 如果您的the_valid_words
中没有空格,那么if the_join==the_valid_words
始终为false。 the_valid_words,
这是您的整个列表)进行比较。 您可能应该使用any_word
...与每个其他未使用的有效单词进行比较。 x
,您可能还会遇到迭代x
的问题(它有时会使迭代器无效……但有时不会)。 即,如果您要遍历x
,然后在完成迭代之前先更改x
,则Python可能不知道迭代器在x
的新版本中的位置。 由于the_list
始终与x
相同,因此最好对for every in the_list:
然后将x
更改为您内心的满足。 看来您可能不太了解for循环在Python中的工作方式。 看看那些,可能会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.