#NEWLINE# def wordPattern( self , pattern , str ) : #NEWLINE# #INDENT# '\n        May not always work due to OneToOneMap implementation in the case that a word is 1-letter.\n\n        :type pattern: str\n        :type str: str\n        :rtype: bool\n        ' #NEWLINE# m = OneToOneMap ( ) #NEWLINE# lst = str . split ( ' ' ) #NEWLINE# if ( len ( pattern ) != len ( lst ) ) : #NEWLINE# #INDENT# return False #NEWLINE# #UNINDENT# for i in xrange ( len ( pattern ) ) : #NEWLINE# #INDENT# a = m . get ( m [ i ] ) #NEWLINE# b = m . get ( lst [ i ] ) #NEWLINE# if ( ( a is None ) and ( b is None ) ) : #NEWLINE# #INDENT# m . set ( pattern [ i ] , lst [ i ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( a is None ) and ( b is not None ) ) : #NEWLINE# #INDENT# return False #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( a != lst [ i ] ) : #NEWLINE# #INDENT# return False #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return True