asked 49.5k views
1 vote
write a python function that takes string j and returns a dictionary showing number of letters and digits in j. The returned dictionary is supposed to have two keys digits and letters. you can take advantage of isdigit() and isalpha() which are methods for string objects showing if a string is digit

1 Answer

5 votes

Step-by-step explanation:

def letterDigitCount(j):

dic={"digits":0,"letters":0}

for a in j:

if a.isdigit():

dic["digits"]+=1

elif a.isalpha():

dic["letters"]+=1

return dic

write a python function that takes string j and returns a dictionary showing number-example-1
write a python function that takes string j and returns a dictionary showing number-example-2
answered
User Clio
by
8.4k points