Count frequency of characters in string Dry Run in PYTHON

Count frequency of characters in string is an interactive PYTHON dry run visualizer from the Dict programs section. Study the source code, then use the execution controls to follow each step, variable update, highlighted line, and console output.

This page provides a browser-based dry run with source-code highlighting, auto-scroll, voice narration controls, and execution output for learning the program step by step.

Count frequency of characters in string Program Code

# Count frequency of characters in a string
text = "programming"
print("String:", text)

# Method 1: Using dictionary
char_freq = {}
for char in text:
    char_freq[char] = char_freq.get(char, 0) + 1

print("Character frequencies:", char_freq)

# Method 2: Case-insensitive
text2 = "Hello World"
char_freq2 = {}
for char in text2.lower():
    char_freq2[char] = char_freq2.get(char, 0) + 1
print(f"\nCase-insensitive for '{text2}': {char_freq2}")

# Display only letters (ignore spaces)
letter_freq = {k: v for k, v in char_freq2.items() if k.isalpha()}
print(f"Letters only: {letter_freq}")

View the complete Dict programs page.

Program Console Count frequency of characters in string Topic: PYTHON Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.