Recipes

From Computer Science Wiki
Jump to: navigation, search
A step-by-step guide for common problems [1]

There are common problems you need to solve when you are designing and building a computer program. Most of the time, someone else has had the exact same problem. This is one reason why sites like stack exchange are helpful. These recipes are here to share easy-to-follow solutions for common problems.

Python: Count the words in a string

wordList = "the quick brown fox jumps over the the lazy lazy dog."
print (len(wordList.split()))

Python: Count the occurrences of words in a corpus

from collections import Counter
wordList = "the quick brown fox jumps over the the lazy lazy dog."
counts = Counter(wordList.split())
print(counts)

References

  1. http://www.flaticon.com/