Downword Slant

Let’s call a word a "downword" if its letters are alphabetically sorted, case-insensitively, right to left. By this definition, Pond is a downword because d comes before n, which comes before o, which comes before P. So too is pool (as oo does not violate this definition), but lake is not because neither e nor k comes before a alphabetically.

Answer the below in downword.txt.

Questions

  1. (1 point.) Is spoonfed a downword?

  2. (1 point.) Is troll a downword?

  3. (2 points.) Now imagine that we call a word an "upword" if its letters are alphabetically sorted, case-insensitively, left to right. Consider the below implementation in Python of upword, a function that returns True if word (a str) is an upword and False if it is not. Assume that downword is a function (implemented elsewhere) that returns True if word is a downword and False if it is not.

    def upword(word):
        return not downword(word)

    Is this implementation of upword correct? Explain why or why not.

  4. (4 points.) Assume now that downword has not (yet!) been implemented elsewhere. Complete the implementation of downword, below, in such a way that it returns True if and only if word (a str) is a downword. Return False if word contains one or more non-alphabetical characters or if the letters in word are not alphabetically sorted, case-insensitively, right to left.

    def downword(word):
        # TODO

Debrief

  1. Which resources, if any, did you find helpful in answering this problem’s questions?

  2. About how long did you spend on this problem’s questions?