-
seeking Help for Comp Ling Methods Homework Assignment: Bigrams
Posted by Shani Tzoref on October 17, 2019 at 7:19 pmHi, 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 bigramspairs = []
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,
ShaniAttachments:
You must be logged in to view attached files.
Public Group active 4 months ago
PUG – Python User’s Group
Python User’ Group (or PUG for short) is an open and informal collaborative space for experimentation and exploration with the Python programming language. It is an opportunity for those interested in Python to work together virtually and find support. Whether you are looking for advice or assistance with new or current projects, looking to discuss and learn new skills using Python tools, or to join us to play around with our collection of sample datasets, PUG is your place!
PUG is open to people of all skill levels, disciplines, and backgrounds. Complete beginners to Python will find a place here. Come, and let’s learn together.
Join PUG Slack here: https://join.slack.com/t/pug-world/shared_invite/zt-iube7uch-nVkvtIyIbpaqtQSZcMB2Ig
PUG is cosponsored by the MA in Digital Humanities / MS in Data Analytics and Visualization programs and the Mina Rees Library.
To learn more, visit http://cuny.is/pug
