Bigrams

danbihan · June 12, 2021
sentence = """
Have free hours and love children? 
Drive kids to school, soccer practice 
and other activities.
"""

def get_bigrams(sentence):
    words = sentence.split(' ')
    words = [word.replace('\n', '').lower() for word in words]
    
    return [(first, second) for first, second in zip(words, words[1:])]

print(get_bigrams(sentence))
Output

Comments

Please sign up or log in to contribute to the discussion.