Question: How do you solve this with Python? Words with given shape def words_with_given_shape (words, shape): The shape of the given word of length n is

 How do you solve this with Python? Words with given shapedef words_with_given_shape (words, shape): The shape of the given word of length

How do you solve this with Python?

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. shape Expected result (using wordlist words_sorted.txt) ['congeed', 'nutseed', strolld'] [1, -1, -1, -1, 0, -1] 'outfeed', [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'] ['aargh', 'eeler' 'eemis', eeten', 'oopak', 'oozes', 'sstor'] ['aegilops'] [0, 1, -1, 1] [1, 1, 1, 1, 1, 1, 1] 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? Chirality def is_left_handed (pips): Even though this has no effect on fairness, pips from one to six are not painted on dice just any which way, but that pips on the opposite faces always add up to seven. (This convention makes it easier to tell when someone tries to use gaffed dice that leave out undesirable pip values.) In each corner of the cube, one value from each pair of opposites 1-6, 2-5 and 3-4 meets two values from the other two pairs of opposites. The math works out for the 23 = 8 corners of the cube. This discipline still allows for two distinct ways to paint these pips. In the corner shared by the faces 1, 2, and 3, read these numbers clockwise starting from 1. If these numbers read out as 1-2-3, that die is left-handed, and if they read out as 1-3-2, that die is right-handed. Analogous to a pair of shoes made separately for the left and right foot, left- and right-handed dice are in one sense identical, and yet no matter how you twist and turn, you can't change either one to become indistinguishable from the other. (Well, at least not without taking that three-dimensional pancake Through the Looking-Glass" by flipping it around in the fourth dimension!) The three numbers read around any other corner stamp the three numbers in the unseen opposite sides, and therefore determine the handedness of that entire die just as firmly. Given the three-tuple of pips around a corner read in clockwise order, determine whether that die is left-handed. There are only 23*3! = 8*6 = 48 possible pip combinations to test for, but you should still find and cheerily exploit as many of the ample symmetries available in this problem as you can. (This problem would also make for an interesting code golf exercise.) pips Expected result (1, 2, 3) True (1, 3, 5) True (5, 3, 1) False (6, 3, 2) True (6, 5, 4) False After solving that, imagine that our physical space had k dimensions, instead of merely just the familiar three. How would dice even be cast (in both senses of this word) in k dimensions? How would you generalize your function to find the chirality of an arbitrary k-dimensional die

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 Databases Questions!