Reference library

Dictionaries & sets

Key–value maps, uniqueness, counting, grouping, and fast lookups.

1 match
Dictionaries & sets easy

How to Count Words and Find Common Words in Python with Dictionaries and Sets

Build a simple text processor that counts unique words with dictionaries and finds common words across text halves using sets.

dictionaries sets word-count
Python
def process_text(text):
    """Process text: count unique words with counts, find common words."""
    words = text.lower().replace(",", "").replace(".", "").split()
    
    word_counts = {}
    for word in words:
        word_counts[word] = word_counts.get(word, 0) + 1
    
    total_words = len(words)
    unique_wo…
13 0 Open

Browse by section

Each section groups closely related Python snippets.

Dictionaries & sets — Python code examples

What you will find here

This page collects dictionaries & sets snippets — short, copy-ready Python you can paste into our free online IDE and run without installing anything. Each sample includes a plain-English explanation and the full source code.

Samples vs tutorials and challenges

Samples are quick reference — one concept per page. For step-by-step teaching, use our Python tutorials. To test yourself, try quizzes or coding challenges. Clean up style with the Python formatter.