Knowee
Questions
Features
Study Tools

Create a list b with elements 'apple', 'banana', 'cherry', and concatenate them into a single string using a space as a separator. Count the occurrences of the word 'is' in the string a. Create a dictionary d with word frequencies from the list b.

Question

Create a list b with elements 'apple', 'banana', 'cherry', and concatenate them into a single string using a space as a separator. Count the occurrences of the word 'is' in the string a. Create a dictionary d with word frequencies from the list b.

🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, I can help you with that. Here are the steps to follow:

Step 1: Create a list b with elements 'apple', 'banana', 'cherry'. b = ['apple', 'banana', 'cherry']

Step 2: Concatenate the elements of the list b into a single string using a space as a separator. string_b = ' '.join(b) print(string_b)

Step 3: Count the occurrences of the word 'is' in the string a. count_is = string_b.count('is') print(count_is)

Step 4: Create a dictionary d with word frequencies from the list b. d = {} for word in b: if word in d: d[word] += 1 else: d[word] = 1 print(d)

I hope this helps! Let me know if you have any further questions.

This problem has been solved

Similar Questions

Question 2: For a given list of strings, please create a new list where each element is the uppercase version of the first letter of a string with a length greater than or equal to 5 in the original list.words = ["apple", "banana", "orange", "mango", "kiwi", "pear"]

Write a function repeat_word_count(text, n) that takes a string text and a positive integer n, converts text into a list of words based on simple whitespace separation (with no removal of punctuation or changing of case), and returns a sorted list of words that occur n or more times in text. For example:>>> repeat_word_count("buffalo buffalo buffalo buffalo", 2)['buffalo']>>> repeat_word_count("one one was a racehorse two two was one too", 3)['one']>>> repeat_word_count("how much wood could a wood chuck chuck", 1)['a', 'chuck', 'could', 'how', 'much', 'wood']

7.22 LAB: Word frequenciesWrite a program that reads a list of words. Then, the program outputs those words and their frequencies. The input begins with an integer indicating the number of words that follow. Assume that the list will always contain fewer than 20 words.Ex: If the input is:5 hey hi Mark hi markthe output is:hey - 1hi - 2Mark - 1hi - 2mark - 1Hint: Use two vectors, one vector for the strings and one vector for the frequencies.

Write a function top5_words(text) that takes a single argument text (a non-empty string), tokenises text into words based on whitespace (once again, without any stripping of punctuation or case normalisation), and returns the top-5 words as a list of strings, in descending order of frequency. If there is a tie in frequency at any point, the words with the same frequency should be sub-sorted alphabetically (e.g. if 'turtle' and 'grok' both occur 5 times, 'grok' should come first). If there are less than five distinct words in text, the function should return all words in descending order of frequency (with the same tie-breaking mechanism). For example:>>> top5_words("one one was a racehorse two two was one too")["one", "two", "was", "a", "racehorse"]>>> top5_words("buffalo buffalo buffalo chicken buffalo")["buffalo", "chicken"]>>> top5_words("the quick brown fox jumped over the lazy dog")["the", "brown", "dog", "fox", "jumped"]

How many words can be made from the word “APPLE” using all the alphabets with repetition and without repetition respectively?

1/2

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.