This repository has been archived by the owner on Jan 20, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
23 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
experiments/multilingual_model_ehri/heatmaps_of_alphabet_distribution/count_characters.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/local/bin/python | ||
# -*- coding: utf-8 -*- | ||
|
||
def count_characters(text): | ||
# Create an empty dictionary to store character occurrences | ||
char_count = {} | ||
|
||
# Iterate through each character in the text | ||
for char in text: | ||
# Check if the character is already in the dictionary | ||
if char in char_count: | ||
# If it is, increment the count | ||
char_count[char] += 1 | ||
else: | ||
# If it's not, add it to the dictionary with a count of 1 | ||
char_count[char] = 1 | ||
|
||
# Print the character occurrences | ||
for char, count in char_count.items(): | ||
print(f"'{char}' = {count}") | ||
|
||
text_to_read = #Content of the text from which characters will be counted | ||
count_characters(text_to_read) |