【发布时间】:2019-01-31 12:33:26
【问题描述】:
这个问题稍微偏离了这两个主题:
How to test if a string contains one of the substrings in a list?
Check if a Python list item contains a string inside another string
因为虽然关系非常密切,但它似乎并没有真正给我所需的答案。我试图对我一直在阅读的内容进行逆向工程,但没有成功。所以这里是:
如果我想打印出“matchers”列表的成员,我该怎么做? :/
myObjs = ['R_obj', 'objectLeft']
sideNames = ['L_','R_', '_L', '_R', 'Right', 'Left', 'right', 'left']
for i in myObjs:
xx = [side in i for side in sideNames]
if any (xx):
print "something is found in " + i
# ================= other attempts at printing: =================
# print [side in i for side in sideNames] <-- gives list of booleans.
# print xx
# print str(sideNames[side]) + "found is in " + i
# print sideNames.side
# print side
# ================= other attempts at printing: =================
基本上我正在尝试打印 sideNames list member 来代替“某物”,但我的不同尝试都给了我错误的语法:/
PS:我感觉我用错了 [] 和 ()
【问题讨论】:
-
所以你想要像
R_ is found in R_obj这样的输出? -
好的,谢谢。这正是我正在寻找的
标签: python arrays string substring