The following lower case letters are written partly below the baseline: g, j, p, q, y. We say that these letters have a descender.

Write a function named hasDescender() that returns a list of those words in a string in which at least one letter has a descender.
A word should appear in the return list at most once, no matter how many letters in it have descenders and no matter how many times the word occurs in the input string.
You may assume that the input string consists of only lower case letters and spaces – no punctuation or upper case letters. The order of words in the returned list does not matter.

Input: a string s that consists of words, separated by spaces Return: a list of words in s that contain at least one descender
For example, the following would be correct output:

will = 'suspicion always haunts the guilty mind'
['suspicion', 'always', 'guilty']

def hasDescender(text, letter):
    list = []
    will = text.split()
    for word in will:
        if word not in result and letter in word:
    return list

will = "suspicion always haunts the guilty mind"
baseline = "g"
print(hasDescender(will, baseline))


but I want my output to be ['suspicion', 'always', 'guilty']

Please help me with this code. I would be very appriciated.

You have the right general idea,except that you want to look for a category of letter forms, not just a single letter; also, the set of letter forms which have a descender ('gjpqy') is constant, so there's no need to pass a list of them as a function argument.

"result" has not been declared so the line below will error. Note that "list" is a reserved word, i.e. Python already uses it, so you should use another variable name.

if word not in result and letter in word:

Your function returns words for one found letter. Use a loop to send each baseline letter to the function, then catch the return word(s), and print all of the words after the additional loop executes. I would suggest that you include a word that has multiple descender letters in it to the test the program's findings.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.