letter counter | Sololearn: Learn to code for FREE!

+1

letter counter

text = input() text_dict = {} #your code goes here text_list = list(text) text_list2 = list(text) for i in range(len(text)): for x in range(len(text)): y = 0 if text_list[x] == text_list2[x]: y = y + 1 text_dict[text_list[i]] = y print(text_dict) can someone please tell me what’s wrong with this? it’s meant to print the number of letters in a word in dictionary format

3/23/2022 11:18:46 AM

Oliver Clayden

4 Answers

New Answer

+2

What does your if condition do? It's same as if True:

+1

Oliver clayden , just some thoughts from my side: ▪︎we do not need 2 text lists ▪︎we need only one for loop it could be done this way: text_list = list(input()) text_dict = {} #text_list = list(text) # is done with input directly #text_list2 = list(text) # not required for char in text_list: if char in text_dict: # if character already exists: increment number text_dict[char] += 1 else: # create new element in dict and set value to 1 text_dict[char] = 1 print(text_dict)

0

text = input() text_dict = {} #your code goes here text_list = list(text) text_list2 = list(text) for i in range(len(text)): y = 0 for x in range(len(text)): if text_list[i] == text[x]: y = y + 1 text_dict[text_list[i]] = y print(text_dict)

0

just solved it