I'm passing two lists for a class DictionaryMaker()
. This will generate a match between words of the item of one list with the item of the other, in order to declare each item as a key and value.
The class and the method work for me, but to make it more precise I wanted to use RegEx and the re.compile
to further refine the matches.
-
I still do not understand very well how the syntax goes, I've read many things and I think the problem is that I'm trying something like:
(r'\b({})\b'.format(i))
-
This check me the word by its limits ( boundarys ), so that only I detect
'foo'
and not'football'
. What happens is that in the other item that is checking'_foo_'
is between low barsI know I should apply
\w*
(I BELIEVE), but I do not know how. -
The thing is, I need you to make me a match even if this word finds it between low bars - >
'foo'
match with'_foo_'
.
How could I achieve it?
import re
chekingList = [u'Hitch_neck_01_proxy', u'Hitch_head_proxy', u'Hitch_chest_proxy',
u'Hitch_spine_04_proxy',u'Hitch_spine_03_proxy', u'Hitch_spine_02_proxy',
u'Hitch_upperarm_r_proxy', u'Hitch_lowerarm_r_proxy', u'Hitch_upperarm_l_proxy',
u'Hitch_lowerarm_l_proxy', u'Hitch_hips_proxy', u'Hitch_upperleg_l_proxy',
u'Hitch_lowerleg_l_proxy', u'Hitch_upperleg_r_proxy', u'Hitch_lowerleg_r_proxy',
u'Hitch_foot_l_proxy', u'Hitch_toes_l_proxy', u'Hitch_foot_r_proxy',
u'Hitch_toes_r_proxy', u'Hitch_hand_l_proxy','nestor_colt_02_nes','maria_perez_04_vie',
'juan_carlos_lara_curso','referendum_julio_jodido']
checkerList = [u'suck_neck_01_target', u'suck_head_target', u'suck_chest_target',
u'suck_spine_04_target',u'suck_spine_03_target', u'suck_spine_02_target',
u'suck_upperarm_r_target', u'suck_lowerarm_r_target', u'suck_upperarm_l_target',
u'suck_lowerarm_l_target', u'suck_hips_target', u'suck_upperleg_l_target',
u'suck_lowerleg_l_target', u'suck_upperleg_r_target', u'suck_lowerleg_r_target',
u'suck_foot_l_target', u'suck_toes_l_target', u'suck_foot_r_target',
u'suck_toes_r_target', u'suck_hand_l_target',]
class DictionaryMaker:
# __INIT__
def __init__(self,listA=None,listB=None):
self.listA = listA
self.listB = listB
# Must Pass first the list what you want as KEYS
# Then pass the list that you want as VALUES
# It Has FIXEDVALUE for TOLERANCE
def Match(self,listA,listB,fixedValue=2):
dictionary = {}
for x,y in [(x,y) for x in listA for y in listB]:
def BreakWord(x):
counter = 0
list2Check = x.split("_")
for i in list2Check:
find = re.compile(r'\b({})\b'.format(i))
if find.search(y):
print ("it Match")
counter += 1
else:
print ("NOT MATCH")
return counter
counter = BreakWord(x)
print counter
if counter >= fixedValue:
dictionary[y] = x
# print the dictionary Created for debugging
for k,v in dictionary.items():
print ("{} < -- is key from : ---- >> {}".format(k,v))
print " "
return dictionary
dict = DictionaryMaker()
DicForTestResult = dict.Match(chekingList,checkerList)