Question: Instructions Each word in your lexicon should also store a list of neighbour words. From the assignment brief, a neighbour of a word w is

Instructions
Each word in your lexicon should also store a list of neighbour words.
From the assignment brief, a neighbour of a word w is a word that:
Is of the same length as w and,
Differs from w by only one letter.
For example, if the word w refers to "cat", then:
"cathy" is not w's neighbour, for they are not of the same length.
"man" is not w's neighbour, for they differ by more than one letter.
"can" is a neighbour of w
"fat" is a neighbour of w
"cot" is a neighbour of w
In this task, you should define a function add_neighbours() that takes one argument, your lexicon, and for every word in your lexicon, populates the list of neighbours that meet the criteria above.
When adding neighbours, you should also ensure that the list of neighbours for each word is in sorted order.
REMINDER: You are NOT allowed to use any of the builtin sorting functions/methods in Python (e.g. sorted() or .sort()).
Once you have written this function, call it on your lexicon to populate the neighbours for each word in your lexicon.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!