0Pricing
NLP Academy · レッスン

単語と文字を数える

基本的な長さと頻度の測定

「単語と文字を数える」はCoddyKit上の無料NLP Academyレッスンです。 これはレッスン3/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはNLP Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 NLP Academyコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

Measuring Text First

Before any fancy analysis, you measure text. Simple counts of characters and words already tell you a lot about a document. 📏

Count Characters With len

The len function returns how many characters a string holds, including spaces and punctuation.

text = "NLP is fun"
print(len(text))  # 10

Spaces Count Too

Remember that whitespace like spaces and newlines are real characters, so they are included in any character count.

Split Into Words

The split method breaks a string on whitespace and returns a list of words, your simplest path to word counting.

words = "one two three".split()
print(words)  # ['one','two','three']

Count the Words

Apply len to the list from split and you get the word count of the whole document.

words = text.split()
print(len(words))  # number of words

Split Is Naive

Plain split treats hello! as one word because punctuation sticks to letters. Good enough to start, but not perfect.

Count Sentences Roughly

A quick sentence estimate is to count periods, question marks, and exclamation points. It is rough but instantly useful.

n = text.count(".") + text.count("?") + text.count("!")

Average Word Length

Divide total letters by word count to get average word length, a small signal about how dense the writing is.

avg = len(text.replace(" ", "")) / len(words)

Counting Specific Substrings

The count method tells you how many times a substring appears, handy for tallying a single target word.

print(text.lower().count("the"))

Unique Words With a Set

Put the word list into a set and its length is the number of unique words, a measure of vocabulary richness.

unique = set(words)
print(len(unique))

Why Counts Matter

These statistics drive real decisions: spam filters flag odd lengths, and readability tools lean on word counts.

Quick Check

Test your grasp of basic Python text counting.

Recap: Counting Text

You can now count characters with len, words with split, unique words with a set, and rough sentences by punctuation. 🔢

よくある質問

「単語と文字を数える」レッスンは無料ですか?

はい。「単語と文字を数える」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、NLP Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 NLP Academyコースには全4レッスンが含まれています。

「単語と文字を数える」で何を学びますか?

基本的な長さと頻度の測定 ブラウザで直接実行するハンズオンコードでNLP Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

NLP Academyを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのNLP Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン3/4です。

「単語と文字を数える」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このNLP Academyレッスンでコードを書いて実行できますか?

はい。すべてのNLP Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. 文字列、文字、エンコーディング
  2. テキストファイルを Python に読み込む
  3. 単語と文字を数える
  4. 初めての単語頻度表を作る
← NLP Academyに戻る