Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,774 questions

51,679 answers

573 users

How to find the number of occurrences (frequency) of each character in a string with Python

1 Answer

0 votes
def count_char(s):
  for i in range(len(s)):
    if len(s) == 0:
      break;
    ch = s[0]
    if ch == ' ' or ch == '\t':
      continue
    print(ch + " - ", s.count(ch))
    s = s.replace(ch, '').strip()

count_char('Python is an interpreted high-level general-purpose programming language')





'''
run:

P -  1
y -  1
t -  3
h -  3
o -  3
n -  6
i -  4
s -  2
a -  5
e -  9
r -  6
p -  4
d -  1
g -  6
- -  2
l -  4
v -  1
u -  2
m -  2

'''

 



answered Jun 5, 2021 by avibootz
...