Question

Write a ruby program to find the number of occurrences of a given word in a...

Write a ruby program to find the number of occurrences of a given word in a string. I managed to come up with this solution.

class count
  
def words(string)

words = string.downcase.split(/[\s,]+/).map {|w| remove_punctuation(w)}

frequency = Hash.new(0)

words.each do |word|
frequency[word] += 1
end

return frequency
end

but I need the format to be


expected: [["love", 3], ["one", 1], ["the", 2], ["red", 1], ["to", 4], ["light", 1] , ["green", 1], ["leads", 3],, ["all", 2], ["you", 1]]

obteve: {"light" => 1, "love" => 3, "all" => 2, "one" => 1, "leads" => 3, "red" => 1, "green" => 1, "o" => 2, "para" => 4, "você" => 1}

E deixe-me mostrar a você as informações na ordem em que esta frase está, com meu resultado aparecendo em uma ordem totalmente diferente.

Homework Answers

Know the answer?
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
Similar Questions
Write a program in python reverse each and every word of the sentence using function taking...
Write a program in python reverse each and every word of the sentence using function taking string as input parameter from user and passing that string into function and also explain the logic ======================================= input: 'Exam is gonna be good' output: 'maxE si annog eb doog' ================ i am trying like this but getting confused '.'join([w::-1] for w in s.split()]) i need more focus on explanations because it is making me confuse i am not clear with concepts so please...
write a code in python Write the following functions below based on their comments. Note Pass...
write a code in python Write the following functions below based on their comments. Note Pass is a key word you can use to have a function the does not do anything. You are only allowed to use what was discussed in the lectures, labs and assignments, and there is no need to import any libraries. #!/usr/bin/python3 #(1 Mark) This function will take in a string of digits and check to see if all the digits in the string are...
JAVA ASSIGNMENT 1. Write program that opens the file and process its contents. Each lines in...
JAVA ASSIGNMENT 1. Write program that opens the file and process its contents. Each lines in the file contains seven numbers,which are the sales number for one week. The numbers are separated by comma.The following line is an example from the file 2541.36,2965.88,1965.32,1845.23,7021.11,9652.74,1469.36. The program should display the following: . The total sales for each week . The average daily sales for each week . The total sales for all of the weeks .The average weekly sales .The week number...
Write a program of wordSearch puzzle that use the following text file as an input. The...
Write a program of wordSearch puzzle that use the following text file as an input. The output should be like this: PIXEL found (left) at (0,9). ( Use JAVA Array ) .Please do not use arrylist and the likes! Hints • The puzzle can be represented as a right-sized two-dimensional array of characters (char). • A String can be converted into a right-sized array of characters via the String method toCharArray. . A word can occur in any of 8...
This is C. Please write it C. 1) Prompt the user to enter a string of...
This is C. Please write it C. 1) Prompt the user to enter a string of their choosing. Store the text in a string. Output the string. (1 pt) Ex: Enter a sample text: we'll continue our quest in space. there will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. nothing ends here; our hopes and our journeys continue! You entered: we'll continue our quest in space. there will be...
1) 2 point charges are separated by a distance of 8 cm. The left charge is...
1) 2 point charges are separated by a distance of 8 cm. The left charge is 48 mC and the right charge is -16mC. Using a full sheet of paper: draw the 2 charges separated by 8cm, centered in the sheet. (if you are missing a ruler estimate 8cm as ⅓ a paper sheet length). [6] a) Draw field lines to indicate the electric fields for this distribution. [4] b) Draw 3 equipotential surfaces, 1 each, that pass: -Through the...
Use Python to Complete the following on a single text file and submit your code and...
Use Python to Complete the following on a single text file and submit your code and your output as separate documents. For each problem create the necessary list objects and write code to perform the following examples: Sum all the items in a list. Multiply all the items in a list. Get the largest number from a list. Get the smallest number from a list. Remove duplicates from a list. Check a list is empty or not. Clone or copy...
Note: Do not use classes or any variables of type string to complete this assignment Write...
Note: Do not use classes or any variables of type string to complete this assignment Write a program that reads in a sequence of characters entered by the user and terminated by a period ('.'). Your program should allow the user to enter multiple lines of input by pressing the enter key at the end of each line. The program should print out a frequency table, sorted in decreasing order by number of occurences, listing each letter that ocurred along...
I've posted this question like 3 times now and I can't seem to find someone that...
I've posted this question like 3 times now and I can't seem to find someone that is able to answer it. Please can someone help me code this? Thank you!! Programming Project #4 – Programmer Jones and the Temple of Gloom Part 1 The stack data structure plays a pivotal role in the design of computer games. Any algorithm that requires the user to retrace their steps is a perfect candidate for using a stack. In this simple game you...
Item 1 In the case below, the original source material is given along with a sample...
Item 1 In the case below, the original source material is given along with a sample of student work. Determine the type of plagiarism by clicking the appropriate radio button. Original Source Material Student Version In contrast to the transmittal model illustrated by the classroom lecture-note taking scenario, the constructivist model places students at the center of the process--actively participating in thinking and discussing ideas while making meaning for themselves. And the professor, instead of being the "sage on the...