Skip to content

Instantly share code, notes, and snippets.

@greggles
Created November 7, 2024 16:08
Show Gist options
  • Save greggles/d4e208847671e0719568fef87ff2517e to your computer and use it in GitHub Desktop.
Save greggles/d4e208847671e0719568fef87ff2517e to your computer and use it in GitHub Desktop.
gemini counting letters in strawberry
greggles@Gregs-MacBook-Pro ~/c/drupalorg (7.x-3.x)> python3 strawberry.py
The letter 's' appears 1 times.
The letter 't' appears 1 times.
The letter 'r' appears 3 times.
The letter 'a' appears 1 times.
The letter 'w' appears 1 times.
The letter 'b' appears 1 times.
The letter 'e' appears 1 times.
The letter 'y' appears 1 times.
greggles@Gregs-MacBook-Pro ~/c/drupalorg (7.x-3.x)> cat strawberry.py
from collections import Counter
# Set the input string
word = "strawberry"
# Count the frequency of each letter using Counter
letter_counts = Counter(word)
# Print the results in a clear format
for letter, count in letter_counts.items():
print(f"The letter '{letter}' appears {count} time
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment