Python Forum

Full Version: getting a word from a list
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have to get a word which contains the longest word containing "e" from a list. how would I go about this a main function has not been provided. this function has been provided

def test_get_longest_e_word():
    print("1.", get_longest_e_word(["Melissa", "Jessie", "Kath", "Amity", "Raeann"]))
    print("2.", get_longest_e_word(["Jo", "Jessie", "Penelope", "Jin", "Raeann", "Pamelita"]))
    etc....
def get_longest_e_word(word_list):

Im having issues with defining word list how would i in the main function refer to to the test function
def get_longest_e_word(l):
    def e_len(val):
        return len(val) if "e" in val else 0
    return max(l, key=e_len)
It works but if by any chance this is your assignment then it explicitly states how it should be implemented:

Quote:Define the get_longest_e_word() function which is passed a list of strings as a parameter. The function returns the word in the list which has the most characters (i.e., the longest word) BUT only words which have 6 or more characters and contain the letter 'e' (or 'E') are considered. If two or more words in the list have the same number of characters as the longest word and both contain the letter 'e' (or 'E'), the function should return the last word from the start of the list which has the most characters.

If the parameter list is empty or if there are no 6 letter or longer words in the list which contain the letter 'e' (or 'E'), the function should return the empty string. For example, the following code:

print("1.", get_longest_e_word(["Melissa", "Jessie", "Kath", "Amity", "Raeann"]))
print("2.", get_longest_e_word(["Jo", "Jessie", "Penelope", "Jin", "Raeann", "Pamelita"]))
print("3.", get_longest_e_word(["Alan", "Melita", "Amity", "Rosalia", "Rositta", "LeeAnne"]))
print("4. ", "***", get_longest_e_word(["Jo", "Jai", "Jen", "Jing", "Joey", "Jess"]), "***", sep = "")
print("5. ", "***", get_longest_e_word([]), "***", sep = "")
print("6.", "***" + get_longest_e_word([""]) + "***")

prints:

1. Melissa
2. Pamelita
3. LeeAnne
4. ******
5. ******
6. ******
"""
def get_longest_e_word(word_list):
return ""
yes this is my assingment yeah i cant ask for code or anything but im really struggling just started coding