How to get Characters Count in Python from a File - onlinetutorialspoint

PROGRAMMINGJava ExamplesC Examples
Java Examples
C Examples
C Tutorials
aws
JAVAEXCEPTIONSCOLLECTIONSSWINGJDBC
EXCEPTIONS
COLLECTIONS
SWING
JDBC
JAVA 8
SPRING
SPRING BOOT
HIBERNATE
PYTHON
PHP
JQUERY
PROGRAMMINGJava ExamplesC Examples
Java Examples
C Examples
C Tutorials
aws
In this tutorial, we will see how to get characters count in python where characters are reading from a file.
Simple source code to get distinct characters count in a file.
I Love my country, make in India !
Reading each character from a file and counting each distinct character.
document_text = open('data','r')
string = document_text.read().lower()
freq = [None] * len(string);
for i in range(0, len(string)):
    freq[i] = 1;
    for j in range(i+1, len(string)):
        if(string[i] == string[j]):
            freq[i] = freq[i] + 1;
            string = string[ : j] + '0' + string[j+1 : ];
print("Characters and their frequencies");
print("--------------------------------")
for i in range(0, len(freq)):
    if(string[i] != ' ' and string[i] != '0'):
        print(string[i] + "-> " + str(freq[i]));
Output:
Characters and their frequencies
---------------------------------
i-> 4
l-> 1
o-> 2
v-> 1
e-> 2
m-> 2
y-> 2
c-> 1
u-> 1
n-> 3
t-> 1
r-> 1
,-> 1
a-> 2
k-> 1
d-> 1
!-> 1
Done!
Happy Learning 🙂

count number of lines characters and words in a file Java
How to Search a file in a Directory using Java
How to get Words Count in Python from a File
Java Program To  Count number of words in a String
Rules to define Python Identifiers
Python Tuple Data Structure in Depth
What are different Python Data Types
Java Program to Find the characters count in String
How to Read CSV File in Python
How to Find Duplicate Words Count in a File
Python – How to create Zip File in Python ?
How to check whether a file exists python ?
How to read a text file in Python ?
How to Convert Python List Of Objects to CSV File
Python – Selenium Download a File in Headless Mode

count number of lines characters and words in a file Java
How to Search a file in a Directory using Java
How to get Words Count in Python from a File
Java Program To  Count number of words in a String
Rules to define Python Identifiers
Python Tuple Data Structure in Depth
What are different Python Data Types
Java Program to Find the characters count in String
How to Read CSV File in Python
How to Find Duplicate Words Count in a File
Python – How to create Zip File in Python ?
How to check whether a file exists python ?
How to read a text file in Python ?
How to Convert Python List Of Objects to CSV File
Python – Selenium Download a File in Headless Mode
 


Δ
 Python – Introduction
 Python – Features
 Python – Install on Windows
 Python – Modes of Program
 Python – Number System
 Python – Identifiers
 Python – Operators
 Python – Ternary Operator
 Python – Command Line Arguments
 Python – Keywords
 Python – Data Types
 Python – Upgrade Python PIP
 Python – Virtual Environment
 Pyhton – Type Casting
 Python – String to Int
 Python – Conditional Statements
 Python – if statement
 Python – *args and **kwargs
 Python – Date Formatting
 Python – Read input from keyboard
 Python – raw_input
 Python – List In Depth
 Python – List Comprehension
 Python – Set in Depth
 Python – Dictionary in Depth
 Python – Tuple in Depth
 Python – Stack Datastructure
 Python – Classes and Objects
 Python – Constructors
 Python – Object Introspection
 Python – Inheritance
 Python – Decorators
 Python – Serialization with Pickle
 Python – Exceptions Handling
 Python – User defined Exceptions
 Python – Multiprocessing
 Python – Default function parameters
 Python – Lambdas Functions
 Python – NumPy Library
 Python – MySQL Connector
 Python – MySQL Create Database
 Python – MySQL Read Data
 Python – MySQL Insert Data
 Python – MySQL Update Records
 Python – MySQL Delete Records
 Python – String Case Conversion
 Howto – Find biggest of 2 numbers
 Howto – Remove duplicates from List
 Howto – Convert any Number to Binary
 Howto  – Merge two Lists
 Howto – Merge two dicts
 Howto – Get Characters Count in a File
 Howto – Get Words Count in a File
 Howto – Remove Spaces from String
 Howto –  Read Env variables
 Howto – Read a text File
 Howto – Read a JSON File
 Howto –  Read Config.ini files
 Howto – Iterate Dictionary
 Howto – Convert List Of Objects to CSV
 Howto – Merge two dict in Python
 Howto – create Zip File
 Howto – Get OS info
 Howto – Get size of Directory
 Howto – Check whether a file exists
 Howto –  Remove key from dictionary
 Howto – Sort Objects
 Howto – Create or Delete Directories
 Howto – Read CSV File
 Howto – Create Python Iterable class
 Howto – Access for loop index
 Howto – Clear all elements from List
 Howto – Remove empty lists from a List
 Howto – Remove special characters from String
 Howto – Sort dictionary by key
 Howto – Filter a list