top of page
learn_data_science.jpg

Data Scientist Program

 

Free Online Data Science Training for Complete Beginners.
 


No prior coding knowledge required!

Character occurrence

Updated: Sep 21, 2021

Think of the len() function, but this method has a much scope enabling you to use of bigger strings or character occurrences. We use dictionaries iterated over by for loops under a function.

In the dictionary, we take count of characters over a loop


# Count character occurrences in a given word, phrase or sentence


def charCount(s):

# create an empty dictionary

charLib=dict()

for i in s:

if i not in charLib:

charLib[i]=0

charLib[i]+=1

return charLib


#test function

occurrences= charCount("ASHIOYA LOVES DATA SCIENCE")

occurrences.pop(' ') # to delete space character if it is in dictionary

for char,occur in occurrences.items():

print(char+" contains "+str(occur)+" times ")


N/B The pop() is ONLY used if it's in a string otherwise it wouold be an error

1 commentaire


Data Insight
Data Insight
20 sept. 2021

Use code snippet functionality to insert your code.

J'aime

COURSES, PROGRAMS & CERTIFICATIONS

 

Advanced Business Analytics Specialization

Applied Data Science with Python (University of Michigan)

Data Analyst Professional Certificate (IBM)

Data Science Professional Certificate (IBM)

Data Science Specialization (John Hopkins University)

Data Science with Python Certification Training 

Data Scientist Career Path

Data Scientist Nano Degree Program

Data Scientist Program

Deep Learning Specialization

Machine Learning Course (Andrew Ng @ Stanford)

Machine Learning, Data Science and Deep Learning

Machine Learning Specialization (University of Washington)

Master Python for Data Science

Mathematics for Machine Learning (Imperial College London)

Programming with Python

Python for Everybody Specialization (University of Michigan)

Python Machine Learning Certification Training

Reinforcement Learning Specialization (University of Alberta)

Join our mailing list

Data Insight participates in affiliate programs and may sometimes get a commission through purchases made through our links without any additional cost to our visitors.

bottom of page