Hi, group.
I would greatly appreciate some debugging help, related to a homework assignment in the Comp Ling Methods I course.
The assigned task was to define a function to list bigrams of a list of strings.
Feeling stuck in the assignment, I decided to try something simpler: rather than defining a function, I tried to create a list of bigrams for a specific list.
For the following list: LSD = [“Lucy”, “in”, “the”, “sky”, “with”, “diamonds”]
I want to produce code to give me a list of word pairs:
[[“Lucy”, “in”], [“in”, “the”], [“the”, “sky”], [“sky”, “with”], [“with”, “diamonds”]]
My attempted code gives me only the strings in the original list, setting them within individual lists, but not as pairs. I’ve attached a PDF of my Jupyter notebook, and will also paste the failed code here:
LSD = [“Lucy”, “in”, “the”, “sky”, “with”, “diamonds”]
#produce list of bigrams
pairs = []
for x in range(len(LSD)):
pair = LSD[x:x +1]
pairs += [pair]
print(pairs)
The result I get is:
[['Lucy'], ['in'], ['the'], ['sky'], ['with'], ['diamonds']]
Thanks,
Shani
Attachments:
You must be
logged in to view attached files.