Re: regular expression dictionary search

2007-08-20 Thread Gabriel Genellina
On 20 ago, 12:48, mkPyVS <[EMAIL PROTECTED]> wrote: > On Aug 20, 9:35 am, "Shawn Milochik" <[EMAIL PROTECTED]> wrote: > > As a side note unless you are searching large buffers it is possibly > more costly to compile into a re object then do a match with it as > opposed to let the match object perfo

Re: regular expression dictionary search

2007-08-20 Thread Shawn Milochik
On 8/20/07, Paul McGuire <[EMAIL PROTECTED]> wrote: > On Aug 20, 10:35 am, "Shawn Milochik" <[EMAIL PROTECTED]> wrote: > > #!/usr/bin/env python > > > if __name__ == "__main__": > > > > print "The return for 'fred' : %s" % returnCode('fred') > > print "The return for 'silk' : %s" % returnC

Re: regular expression dictionary search

2007-08-20 Thread Paul McGuire
On Aug 20, 10:35 am, "Shawn Milochik" <[EMAIL PROTECTED]> wrote: > #!/usr/bin/env python > if __name__ == "__main__": > > print "The return for 'fred' : %s" % returnCode('fred') > print "The return for 'silk' : %s" % returnCode('silk') > print "The return for 'silky' : %s" % returnCode

Re: regular expression dictionary search

2007-08-20 Thread mkPyVS
On Aug 20, 9:35 am, "Shawn Milochik" <[EMAIL PROTECTED]> wrote: > #!/usr/bin/env python > > import re > > patterns = { 'sho.' : 6, '.ilk' : 8, '.an.' : 78 } > > def returnCode(aWord): > for k in patterns: > p = "^%s$" % k > regex = re.compile(p) > if re.match(regex, aWor

Re: regular expression dictionary search

2007-08-20 Thread Shawn Milochik
#!/usr/bin/env python import re patterns = { 'sho.' : 6, '.ilk' : 8, '.an.' : 78 } def returnCode(aWord): for k in patterns: p = "^%s$" % k regex = re.compile(p) if re.match(regex, aWord): return patterns[k] if __name__ == "__main__": print "The retu

regular expression dictionary search

2007-08-20 Thread dorje tarap
Hi I have a dictionary with a list of patterns: Code: ( text ) 1. >>> words = {'sho.':6, '.ilk':8,'.an.':78 } Where the "." character means any pattern - this can easily be changed to the "*" symbol if need be. When the user submits a word, I want to be able to look for a corresponding pat