Question

python program- ---create a function that returns the longest word inside a list of words ---create...

python program-

---create a function that returns the longest word inside a list of words

---create a function with two parameters (phrase,wordList) that returns a count of how many words are spelled incorrectly that cannot be found in wordList (a list of words)

for both you can only use these functions --- append, len, str, float, range, strip, split, int.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Python code:

#function which checks for the longest word

def longword(words):

    #initializing length of longest word

    maxlen=0

    #checking each word in list

    for i in words:

        #checking if length of current word is greater than maxlen

        if(len(i)>maxlen):

            #setting current word as longest word

            word=i

            #setting maxlen as length of current word

            maxlen=len(word)

    #returning longest word

    return word

#function which checks for count of word spelled incorrectly

def wordcount(phrase,wordList):

    #initializing count as 0

    count=0

    #checking each word in phrase

    for i in phrase.split():

        #checking if word is in wordList

        if(i not in wordList):

            #incrementing count

            count+=1

    #returning count

    return count

#testing longword function and printing

print(longword(["i","is","are","hi","am"]))

#testing wordcount function and printing

print(wordcount("hi i am rahul",["i","is","are","hi","am"]))

Screenshot:

1 #function which checks for the longest word 2. def longword(words): 3 #initializing Length of Longest word 4 maxlen=0 5 #ch

Output:

are i

Add a comment
Know the answer?
Add Answer to:
python program- ---create a function that returns the longest word inside a list of words ---create...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • PYTHON --create a program that accepts a list of words and returns the longest word inside...

    PYTHON --create a program that accepts a list of words and returns the longest word inside that list can only use --- append, len, str, float, range, strip, split, int --create a program that accepts a list of words and a specific length. function will returns a new list that contains the words found with the specific length, and return an empty list if none are found can only use --- append, len, str, float, range, strip, split, int

  •    PYTHON --create a function that accepts a list of numbers and an int that returns...

       PYTHON --create a function that accepts a list of numbers and an int that returns index of 2nd occurrence of the int in list, otherwise returns None if # does not repeat more 2 or more times EX: [10,24,3,45,10,49,4,5], 10) returns 4 --create a function that accepts a string that returns true if every letter of the alphabet can be found at least one time in the string, (has to be the lowercase alphabet), and false otherwise.    for...

  • PYTHON The function longest that returns the longest of two strings. The function count_over that takes...

    PYTHON The function longest that returns the longest of two strings. The function count_over that takes a list of numbers and an integer nand returns the count of the numbers that are over n. The function bmi that takes two parameters height and weight and returns the value of the body mass index: a person's weight in kg divided by the square of their height in meters. def longest(string1, string2): """Return the longest string from the two arguments, if the...

  • python function will Return True if string x contains 3 vowels in a row, in consecutive...

    python function will Return True if string x contains 3 vowels in a row, in consecutive locations, false otherwise. assuming that 'vowels' refer to the following lowercase lttrs: a,e,i,o,u programs fails partially, only allowed to use float, str, int, appen, split, strip, len, range def vowels_three(x): for i in range (o, len(x), 2): if x[i] not in ('a,e,i,o,u'): return False return True

  • Python: Create a function count_target_in_list that takes a list of integers and the target value then...

    Python: Create a function count_target_in_list that takes a list of integers and the target value then counts and returns the number of times the target value appears in the list. Write program in that uses get_int_list_from_user method to get a list of 10 numbers, then calls the count_target_list method to get the count then prints the number of times the target was found in the list. def get_int_list_from_user(): lst=[] y = int(input("Enter number of numbers")) for x in range(y): lst.append(int(input("Enter...

  • Implement the function odd_total (xs) that takes a list of list of ints xs and returns...

    Implement the function odd_total (xs) that takes a list of list of ints xs and returns the sum of the odd numbers but skips the numbers on the first row and the last column of xs. You're not allowed to modify xs. You can't use any built-in function or method except int, str, range and len. Example: odd_total ([[1,2,3],[4,5,6], [7,8,9]]) - - > 12

  • In Python 3 only please. A simple function that will be used on a file. commonpair(str)...

    In Python 3 only please. A simple function that will be used on a file. commonpair(str) – Takes a single string argument, representing the first word. This function should return the word that most frequently followed the given argument word (or one of, in case of ties). If the argument word does not appear in the text at all, or is never followed by another word (i.e., is the last word in the file), this function should return None. I...

  • python please 11 def add_item(items, word): 14 15 16 F # check if the word is...

    python please 11 def add_item(items, word): 14 15 16 F # check if the word is in the dictionary (keys of dictionary) if word in items: items [word] = items (word] + 1 # update the count else: # word is not in dictionary items[word] = 1 # add the word with count 1 return items [word] # return the current count of word after updation Create a function named build_dictionary that takes a list of words (as a parameter)...

  • Using Python, if you could help me with the code # Create a modified version of the search linear function defined # above to return all # occurrences of the search word in the text # An occurrence is...

    Using Python, if you could help me with the code # Create a modified version of the search linear function defined # above to return all # occurrences of the search word in the text # An occurrence is the index of a word in the text that matches your given # search string. # e.g. if "hatter" occurs at positions 0, 6, 12 then return [ 0, 6, 12] def search_linear_occurrences(xs, target): """ Find and return a list of...

  • In python Count the frequency of each word in a text file. Let the user choose...

    In python Count the frequency of each word in a text file. Let the user choose a filename to read. 1. The program will count the frequency with which each word appears in the text. 2. Words which are the spelled the same but differ by case will be combined. 3. Punctuation should be removed 4. If the file does not exist, use a ‘try-execption’ block to handle the error 5. Output will list the words alphabetically, with the word...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT