#NEWLINE# def position_of_ngram( ngram , sentence ) : #NEWLINE# #INDENT# "\n    This function returns the position of the first instance of the ngram \n    appearing in a sentence.\n    \n    Note that one could also use string as follows but the code is a little\n    convoluted with type casting back and forth:\n        \n        char_pos = ' '.join(sent)[:' '.join(sent).index(' '.join(ngram))]\n        word_pos = char_pos.count(' ')\n        \n    Another way to conceive this is:\n    \n        return next(i for i, ng in enumerate(ngrams(sentence, len(ngram))) \n                    if ng == ngram)\n                    \n    :param ngram: The ngram that needs to be searched\n    :type ngram: tuple\n    :param sentence: The list of tokens to search from.\n    :type sentence: list(str)\n    " #NEWLINE# for ( i , sublist ) in enumerate ( ngrams ( i , len ( ngram ) ) ) : #NEWLINE# #INDENT# if ( ngram == sublist ) : #NEWLINE# #INDENT# return i