builds the list of words from there

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

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
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']
Transcribed Image 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']
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY