【发布时间】:2018-07-10 07:09:41
【问题描述】:
这是我的代码:
keyinput = input() # I type 'appleandgold'
B = 'appleblue'
if keyinput in B: # Should actually be keyinput "intersects" B
print(keyinput) # Should print intersection
keyinput = 'appleandgold' 和B = 'appleblue' 的结果(打印值)应该是'apple',但我只能让它为keyinput = 'apple' 工作。
【问题讨论】:
-
how i print results为其添加代码] -
所以你正在寻找一种方法来找到最长的公共子串?顺便说一句,
type并没有按照你的想法去做。 -
您的代码在语法上是错误的 (
If?),包含多余的行(type没有按照您的想法执行)并且无论如何都会失败("appleandgold"不是in "appleblue")。 -
代码看起来如何,我想要 IF .. IN .. statment 的结果?
-
您需要更好地定义您的问题。你在寻找两个词的最长公共子串吗?查看此链接以获取解决方案。 bogotobogo.com/python/…
标签: python string python-3.x intersection in-operator