Letter counter (dictionary output) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Letter counter (dictionary output)

text = input() dict1 = {} #your code goes here letters1 = [] count1 = [] for i in text: if i not in letters1: letters1.append(i) else: continue for k in letters1: if k==" ": continue else: count1.append(text.count(k)) for l in range(len(letters1)): dict1[letters1[l]]=count1[l] print(dict1) #Hello everyone, i wrote this and it's working. But how can it be more short ?

10th Jul 2022, 11:03 PM
Özgür Öztürk
3 Answers
0
Btw the task is "Creating a program to take a string as input and output a dictionary, which represents the letter count." Example ; İnput : hello Output : {'h':1, 'e':1, 'l':2, 'o': 1}
10th Jul 2022, 11:24 PM
Özgür Öztürk
0
Hahaha thanks 😂
10th Jul 2022, 11:45 PM
Özgür Öztürk