0

This question slightly branches off of these two topics:

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

Because while it's very closely related, it doesn't really seem to give me the answer i need. I've tried to reverse engineer what I've been reading to no success. so here goes:

what If I wanted to print out the member of the "matchers" list, how do I go about it? :/

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:  =================

Basically I'm trying to print the sideNames list member in place of "something", but my different attempts have all been giving me wrong syntaxes :/

PS: I have a feeling that im using [] and () incorrectly

1 Answers1

1
myObjs = ['R_obj', 'objectLeft']
sideNames = ['L_','R_', '_L', '_R', 'Right', 'Left', 'right', 'left']

for i in myObjs:
    for side in sideNames:
        if side in i:
            print side, "is found in ", i

will give the result:

R_ is found in  R_obj
Left is found in  objectLeft
Travis
  • 109
  • 5