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 speci0ied in this document that operate on lists of words, should not itself try to read the wordlist 0ile 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 0ile it came from. shape Expected result (using wordlist words_sorted.txt) [1, -1, -1, -1, 0, -1] ['congeed', 'nutseed', 'outfeed', 'strolld'] [1, -1, -1, 0, -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'] Motivated students can take on as a recreational challenge to 0ind 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?

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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 speci0ied in this document that operate on lists of words, should not itself try to read the wordlist 0ile 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 0ile it came from.

shape

Expected result (using wordlist words_sorted.txt)

[1, -1, -1, -1, 0, -1]
['congeed', 'nutseed', 'outfeed', 'strolld']
[1, -1, -1, 0, -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']

Motivated students can take on as a recreational challenge to 0ind 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?

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Problems on Dynamic Programming
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education