Dark theme

Hints


This seems complicated, but the actual algorithm can be written in Python with very little code. Here it is:

  1. Connect to the site and get its content.
  2. Navigate the DOM to the element around the poem and get its text attached to a variable label.
  3. Cut out any elements of the text you don't want.
  4. Make a counter (see below).
  5. Loop i through to range(len(text) - 1)
  6. Taking text[i] + " " + text[i+1] as the key, increment the counter by one.
  7. End the i loop.
  8. Print the most common elements from the counter.

Remember, build it up a line at a time, testing what each line gives you before moving on.

Libraries that would help include requests; bs4; collections. Functions that would help include: str.replace(); str.split(); see also the lecture on libraries to see how to use collections.Counter.


One answer