+1 vote
in Python by
Write a function that can take a string and return a list of bigrams.

1 Answer

0 votes
by

Example:

sentence = """

Have free hours and love children?

"""

output = [('have', 'free'),

('free', 'hours'),

('hours', 'and'),

('and', 'love'),

('love', 'children?')]

When separating a sentence into bigrams, the first thing we need to do is split the sentence into individual words. We would need to loop through each word of the sentence and append bigrams to the list. How many loops would we need, for instance, if the amount of words in a sentence was equal to k?

Related questions

0 votes
asked Sep 7, 2022 in Python by sharadyadav1986
+1 vote
asked Feb 15, 2021 in Python by SakshiSharma
...