In [1]:
def contar_lyn(texto):
res = {'letras': 0, 'numeros': 0}
for i in texto:
if i.isdigit():
res['numeros'] += 1
elif i.isalpha():
res['letras'] += 1
return res
In [2]:
contar_lyn("abcde+1234")
Out[2]:
In [4]:
def contar_letras(texto):
res = {}
for i in texto.lower():
if i in res.keys():
res[i] += 1
else:
res[i] = 1
return res
In [5]:
contar_letras("paralelepipedo")
Out[5]:
In [6]:
diccionario = contar_letras("paralelepipedo")
In [7]:
diccionario.keys()
Out[7]:
In [13]:
for i in diccionario.keys():
print(i, diccionario[i])
In [9]:
diccionario.values()
Out[9]:
In [10]:
len(diccionario)
Out[10]:
In [12]:
for i in diccionario:
print(i)