From ddf19ab2dd8a6787f97a6ac021471486f68cb2a8 Mon Sep 17 00:00:00 2001 From: yashkumarjha12 <72943344+yashkumarjha12@users.noreply.github.com> Date: Thu, 6 Oct 2022 11:31:08 +0530 Subject: [PATCH] Create Count_occurence.py --- Python/Count_occurence.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Python/Count_occurence.py diff --git a/Python/Count_occurence.py b/Python/Count_occurence.py new file mode 100644 index 0000000..0b42994 --- /dev/null +++ b/Python/Count_occurence.py @@ -0,0 +1,15 @@ +# Question :- Write a function which takes a string as input and prints total occurrences of each character. + +def charOccur(s): + occurence = {} + + for i in s: + if i in occurence: + occurence[i]=occurence[i]+1 + else: + occurence[i]=1 + + return occurence + +string1 = input('Enter a string:- ') +print(charOccur(string1))