Word count that counts only words that start with a capital letter in python

While writing natural language processing in python, there was a scene where I wrote a counter with only uppercase letters, so make a note so as not to forget ・ Counting words starting with a capital letter ・ Only when only the beginning of a word is capitalized ・ For uppercase letters + numbers, etc.

import re
from collections import Counter

org_text = """
Of course a writer can write from the viewpoint of Southern slave owners who of course would be racist and 
view black people with, at best, benevolent paternalism, without her characters' 
attitudes necessarily being her own. But it's very apparent that Mitchell was wholly and uncritically sympathetic to her antebellum ancestors. 
The Old South was a graceful, chivalrous land where slavery was not a horrible and oppressive institution creating generations of misery and oppression, 
but a divinely-ordained means of preserving racial harmony. And for all that Mitchell, 
like her characters, probably considered herself to be kind and affectionate to all the African-Americans she knew personally, 
there isn't a single black character in the book who isn't an ignorant, semi-human ape -- which is literally how they are described. 
Even beloved Mammy is repeatedly compared to a monkey.
"""

#Separate strings into an array
words= re.split(r'\s|\,|\.|\(|\)',org_text)

#Extract only words starting with a capital letter
r = re.compile("^[A-Z]$|^[A-Z][a-z0-9]+$")
dict_word=[x for x in words if r.match(x)]

counter=Counter(dict_word)

for word,count in counter.most_common():
    print("%s,%d" % (word,count))


Recommended Posts

Word count that counts only words that start with a capital letter in python
[Python] Leave only the elements that start with a specific character string in the array
Let's create a script that registers with Ideone.com in Python.
Create a word cloud with only positive / negative words on Twitter
Spiral book in Python! Python with a spiral book! (Chapter 14 ~)
[Python] A program that creates stairs with #
Create a word frequency counter with Python 3.4
A typed world that begins with Python
[Automation] Read a Word document with Python
A story that turned light blue in 4 months after starting AtCoder with python
I registered PyQCheck, a library that can perform QuickCheck with Python, in PyPI.
I made a familiar function that can be used in statistics with Python
[Python] Get the files in a folder with Python
A memo that I wrote a quicksort in Python
Start Django in a virtual environment with Pipenv
Create a virtual environment with conda in Python
Create a page that loads infinitely with python
A program that removes duplicate statements in Python
Start a simple Python web server with Docker
Work in a virtual environment with Python virtualenv.
Create a new page in confluence with Python
Formulas that appear in Doing Math with Python
Create a discord bot that notifies unilaterally with python (use only requests and json)
Create an exe file that works in a Windows environment without Python with PyInstaller
Create a flag in settings that will be True only when testing with Django
It seems that a new lottery with a total score will start in the sports lottery,
Python2 / numpy> Replace only a specific column in a file with column data from another file> numpy.c_
How to convert / restore a string with [] in python
[Python] A program that counts the number of valleys
Playing with a user-local artificial intelligence API in Python
Make a simple Slackbot with interactive button in python
Try embedding Python in a C ++ program with pybind11
Use Cursur that closes automatically with sqlite3 in Python
I want to work with a robot in python.
What's in that variable (when running a Python script)
In Python, create a decorator that dynamically accepts arguments Create a decorator
A addictive point in "Bayesian inference experience with Python"
A server that echoes data POSTed with flask / python
A memo that I touched the Datastore with python
Start numerical calculation in Python (with Homebrew and pip)
Run a Python file with relative import in PyCharm
Create a fake Minecraft server in Python with Quarry
Extract only elements that meet specific conditions in Python
MALSS, a tool that supports machine learning in Python
A story that went missing when I specified a path starting with a tilde (~) in python open
I made a program to collect images in tweets that I liked on twitter with Python
Workaround for the problem that sys.argv is not passed when executing a Python script with only the file name in Python2.7 on Windows
A memo that reads data from dashDB with Python & Spark
Try running python in a Django environment created with pipenv
Design and test Verilog in Python only with Veriloggen and cocotb.
A Python program in "A book that gently teaches difficult programming"
I made a simple typing game with tkinter in Python
Word Count with Apache Spark and python (Mac OS X)
A general-purpose program that formats Linux command strings in python
A function that divides iterable into N pieces in Python
Published a library that hides character data in Python images
Create a list in Python with all followers on twitter
Loop through a generator that returns a date iterator in Python
Solve word counts (equivalent to paiza rank C) in Python
Create a child account for connect with Stripe in Python
A word that I was interested in as a programming beginner