0

How to fix this?

text = input() dict = {} for x in text: keys= dict.keys() if x in keys: dict[x] += 1 else: dict[x] = 1 print(dict)

25th Feb 2022, 3:43 AM
Bluegray
Bluegray - avatar
5 Respostas
+ 7
text = input() dict = {} for x in text: dict[x]=dict.get(x,0)+1 print(dict)
25th Feb 2022, 7:42 AM
Oma Falk
Oma Falk - avatar
+ 5
if and else should be in the same block. for(): if(): #some code else: #some code
25th Feb 2022, 3:47 AM
Simba
Simba - avatar
+ 2
Can you show the link I dont understand him
25th Feb 2022, 4:27 AM
Bluegray
Bluegray - avatar
25th Feb 2022, 3:52 AM
Bluegray
Bluegray - avatar
+ 1
Coding Berries and Cream You need else part also if x is not in keys text = input() dict = {} for x in text: keys= dict.keys() if x in keys: dict[x] += 1 else: #this is also needed dict[x] = 1 else: dict[x] = 1 print(dict)
25th Feb 2022, 5:58 AM
A͢J
A͢J - avatar