+ 3

[Challenge]write a python code for this?

Write a function that accepts a multiple line string as argument, counts the number of alphabets, digits, punctuation marks (, . : ; ' ") and spaces. Prepare a dictionary which has the above said elements as keys and their counts as values

10th Oct 2017, 1:16 PM
sadiya zainab
sadiya zainab - avatar
2 Answers
+ 3
def fun(d,s): alist=['"',';','.',','] for line in d: eachchar=line.split() for eachchar in line: if eachchar.isalpha(): d['char']+=1 elif eachchar.isdigit(): d['digits']+=1 elif eachchar.isspace(): d['whitespace']+=1 elif eachchar in alist: d['punctuations']+=1 print(d) s=input("enter a string") d={'char':0,'digits':0,'whitespace':0,'punctuations':0} fun(d,s)
10th Oct 2017, 4:25 PM
sadiya zainab
sadiya zainab - avatar
+ 1
string = str("ASjdoiajsd ioaoidkad,as.d,.as,(*(&(*7af097a0f\n" "ASjdoiajsd ioaoidkad,as.d,.as,(*(&(*7af097a0f\n" "ASjdoiajsd ioaoidkad,as.d,.as,(*(&(*7af097a0f") out = {} for s in string: if s in out: out[s]+=1 else: out[s]=1 print(out)
10th Oct 2017, 2:23 PM
nevu
nevu - avatar