I’ve downloaded the double metaphone function: https://github.com/dracos/double-metaphone
It’ supposed to work like this:
>>> dm(u'aubrey')
('APR', '')
>>> dm(u'richard')
('RXRT', 'RKRT')
>>> dm(u'katherine') == dm(u'catherine')
True
How do I pass a variable to this function? The u is always in the way. I need to be able to do
dm(x)==dm(y)
right now this is what happens:
>>> x='wal mart'
>>> y='wall mart'
>>> dm(x)==dm(y)
Traceback (most recent call last):
File "<pyshell#35>", line 1, in <module>
dm(x)==dm(y)
File "<pyshell#18>", line 6, in dm
st = ''.join((c for c in unicodedata.normalize('NFD', st) if unicodedata.category(c) != 'Mn'))
TypeError: normalize() argument 2 must be unicode, not str
u''is the syntax for a literalunicodestring object, comparable to a regularstrobject except that it can handle Unicode characters.As long as your input is accepted by the function you’re calling, you don’t need the
u. For example:You receive TypeError because the function expects
unicodeobjects and you are passing itstrobjects. Change these lines:To:
If you will be working with
strobjects, then you can convert them tounicodeobjects using theunicode()constructor: