Word Count

Question: Define a function 'wc' that takes in a string or list of strings and returns a dictionary with the keys being the distinct words and the values being the corresponding number of occurrences of the word in the string(s). Non-alphanumeric characters should be ignored and words with different casing should count towards the same word.

Example

                                
                                q)wc "The teacher teaches 26 third-grade students in the classroom. The students took a quiz and scored very well!"
"the"      | 3
"teacher"  | 1
"teaches"  | 1
"26"       | 1
"third"    | 1
"grade"    | 1
"students" | 2
"in"       | 1
"classroom"| 1
"took"     | 1
,"a"       | 1
"quiz"     | 1
"and"      | 1
"scored"   | 1
"very"     | 1
"well"     | 1
q)wc ("A horse is a horse, of course, of course,";"And no one can talk to a horse of course,";"That is, of course, unless the horse is the famous Mr. Ed.")
,"a"    | 3
"horse" | 4
"is"    | 3
"of"    | 4
"course"| 4
"and"   | 1
"no"    | 1
"one"   | 1
"can"   | 1
"talk"  | 1
"to"    | 1
"that"  | 1
"unless"| 1
"the"   | 2
"famous"| 1
"mr"    | 1
"ed"    | 1
                                
                            

Solution

Tags:
dictionaries functions strings
Searchable Tags
algorithms api architecture asynchronous c csv data structures dictionaries disk feedhandler finance functions ingestion ipc iterators machine learning math multithreading optimizations realtime shared library sql statistics streaming strings tables temporal utility websockets