Skip to content

Instantly share code, notes, and snippets.

@civic
Created February 16, 2017 06:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save civic/ddc4e68b22d9dcacc027cddf0d233b8c to your computer and use it in GitHub Desktop.
Save civic/ddc4e68b22d9dcacc027cddf0d233b8c to your computer and use it in GitHub Desktop.
あたえられた文字列中に含まれる単語の個数を単語ごとにカウントするpython
import collections
import re
text = "I have a pen. I have a apple. oh!! Apple pen! I have a pen. I have a pineapple. oh!! Pineapple pen! Apple pen. Pineapplepen. Pen pineapple apple pen."
collections.Counter(s.lower() for s in re.split(r'[^\w]+',text))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment