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

User MattClarke
by
4.5k points

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
User Clio
by
5.5k points