Answer to Question #250214 in Python for binnu

Question #250214

Implement the below function to print the count of numeric characters (0-9) in a given string and also print the count of remaining characters. (Ignore the character cases, it can be lower or upper case)


The function will take 1 parameter which will be a String (or a character array). You do not have to write code to get the input parameter from the user.


int frequencyOfNumericChars(String input) {

          // TODO: Add code here

}


Example:

Input: raja1123labs Output:=’1’=2, ‘2’=1, ‘3’=1, others=8

Input: Buffet101 Output: ‘1’=2, ‘0’=1, others=6



1
Expert's answer
2021-10-13T00:29:43-0400
str1 = "raja1123labs";  
fy = [None] * len(str1);  
   
for i in range(0, len(str1)):  
    fy[i] = 1;  
    for j in range(i+1, len(str1)):  
        if(str1[i] == str1[j]):  
            fy[i] = fy[i] + 1;   
            str1 = str1[ : j] + '0' + str1[j+1 : ];  
                 
for i in range(0, len(fy)):  
    if(str1[i] != ' ' and str1[i] != '0'):  
        print(str1[i] + "-" + str(fy[i])); 

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS