Can anybody help with a function to convert the following ngram into the result below? The return should concatenate the first N-1 elements of the ngram and count how often the different successors (Nth element) occur. I was thinking of some nested for loops, but I am struggling to build a structure. Thanks a lot!!
ngrams = [['will', 'leave', 'florida'], ['will', 'leave', 'nyc'], ['will', 'leave', 'florida'],['wont', 'leave', 'florida']]
The return should be:
{'will leave': {'florida': 2, 'nyc': 1}, 'wont leave': {'florida': 1}}