在Python中检查单词的行和列
我正在尝试创建一个检查程序来查看该单词是否在水平或垂直矩阵中。我有检查行的代码,但是检查列是否与行代码类似?
def checkRow(table, r, pos, word):
for i in range(0, len(word)):
if table[r][pos+i] != word[i]:
return False
return True
示例表如下所示:
[
['a','p','p','l','e','b'],
['u','y','c','v','a','s'],
['n','u','t','o','n','s'],
['t','n','c','v','d','b'],
['o','r','i','x','o','f'],
['e','a','t','i','n','g']
]
I am trying to create a checking program to see if the word is in a matrix horizontally or vertically. I have the code for checking the row, but would checking the column be similar to the row code?
def checkRow(table, r, pos, word):
for i in range(0, len(word)):
if table[r][pos+i] != word[i]:
return False
return True
a sample table would be like this:
[
['a','p','p','l','e','b'],
['u','y','c','v','a','s'],
['n','u','t','o','n','s'],
['t','n','c','v','d','b'],
['o','r','i','x','o','f'],
['e','a','t','i','n','g']
]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
是不是很简单就是这样:
Isn't it simple like this:
OP 表示“他们还没有了解导入”,因此他们宁愿重新发明轮子,也不愿重用标准库中的功能。一般来说,这将是一个相当荒谬的立场,但在这种情况下,它甚至还不算太糟糕:
我希望至少诸如
all
和zip
之类的内置函数是可以接受的 - - 或者OP宁愿将二进制机器语言编码为裸机以避免学习一些 Python?-)The OP indicates "they haven't learned about import yet" so they'd rather reinvent the wheel than reuse functionality in the standard library. In general, that would be a pretty absurd stance, but in this case it ain't even too bad:
I hope at least builtins such as
all
andzip
are acceptable -- or would the OP rather code binary machine language down to the bare metal to avoid learning some Python?-)