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)
7 Antworten
+ 7
text = input()
dict = {}
for x in text:
dict[x]=dict.get(x,0)+1
print(dict)
+ 5
if and else should be in the same block.
for():
if():
#some code
else:
#some code
+ 2
Can you show the link I dont understand him
+ 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)