【发布时间】:2022-01-18 13:12:57
【问题描述】:
上下文:我想制作多词搜索网格
我有一个这样的文本行输入(包含数字和字母字符串):
2 <--- tells how many grids/boxes
3 <--- tells rows/length
4 <--- tells columns/width
catt <--\
aata <--- letters that will fill the box
tatc <--/
cat <--- the word that will be search inside the box
5 <--- and repeat but start with the rows
5
gogog
ooooo
godog
ooooo
gogog
dog
所有这些都在一个列表中作为输入
但是,我需要在里面传递变量。所以我假设我需要将列表拆分/切片为另一个列表,其中包含我需要的所有变量。
我想我需要像这样拆分 cat 和 dog 的变量:
#variables for cat and dog
rows, cols = [3, 5], [4, 5] #the numbers have to be integer
matrix = [['catt', 'aata', 'tatc'], ['gogog', 'ooooo', 'godog', 'ooooo', 'gogog']]
word = ['cat', 'dog']
这些是我需要的变量。但我不知道如何从上面的输入中拆分它。
如果有任何不同的方式,请随时解释。谢谢
【问题讨论】:
-
"cattaatatatc" 有一瞬间我以为这是 DNA。但后来一只狗出现了。