Words with given shape def words_with_given_shape(words, shape): The shape of the given word of length n is a list of n - 1 integers, each one either -1, 0 or +1 to indicate whether the next letter...



Words with given shape

def words_with_given_shape(words, shape):


The shape of the given word of length n is a list of n - 1 integers, each one either -1, 0 or +1 to indicate whether the next letter following the letter in that position comes later (+1), is the same (0) or comes earlier (-1) in the alphabetical order of English letters. For example, the shape of the word

'hello' is [-1, +1, 0, +1], whereas the shape of 'world' is [-1, +1, -1, -1]. Find

and return a list of all words that have that particular shape, listed in alphabetical order.



Note that your function, same as all the other functions specified in this document that operate on lists of words, should not itself try to read the wordlist file words_sorted.txt, even when Python makes this possible with just a couple of lines of code. The tester script already reads in the

entire wordlist and builds the list of words from there. Your function should use this given list of words without even caring which particular file it came from.



Motivated students can take on as a recreational challenge to find the shape of length n - 1 that matches the largest number of words, for the possible values of n from 3 to 20. Alternatively, try to count how many possible shapes of length n - 1 do not match any words of length n at all. What is the shortest possible shape that does not match any words?


Expected result (using wordlist<br>words_sorted.txt)<br>shape<br>[1, -1, -1, -1, 0, -1]<br>['congeed', 'nutseed', 'outfeed',<br>'strolld']<br>[1, -1, -1, о, -1, 1]<br>['<br>axseeds', 'brogger', 'cheddar',<br>'coiffes', 'crommel', 'djibbah',<br>'droller', ' fligger', 'frigger',<br>'frogger', 'griffes', 'grogger',<br>'grommet', 'prigger', 'proffer',<br>'progger', 'proller', 'quokkas',<br>'stiffen', 'stiffer', 'stollen',<br>'swigger', 'swollen', 'twiggen',<br>'twigger']<br>[0, 1, -1, 1]<br>['aargh', 'eeler', 'eemis', 'eeten',<br>'oopak', 'oozes', 'sstor']<br>[1, 1, 1, 1, 1, 1, 1]<br>['aegilops']<br>

Extracted text: Expected result (using wordlist words_sorted.txt) shape [1, -1, -1, -1, 0, -1] ['congeed', 'nutseed', 'outfeed', 'strolld'] [1, -1, -1, о, -1, 1] [' axseeds', 'brogger', 'cheddar', 'coiffes', 'crommel', 'djibbah', 'droller', ' fligger', 'frigger', 'frogger', 'griffes', 'grogger', 'grommet', 'prigger', 'proffer', 'progger', 'proller', 'quokkas', 'stiffen', 'stiffer', 'stollen', 'swigger', 'swollen', 'twiggen', 'twigger'] [0, 1, -1, 1] ['aargh', 'eeler', 'eemis', 'eeten', 'oopak', 'oozes', 'sstor'] [1, 1, 1, 1, 1, 1, 1] ['aegilops']
Jun 10, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here