+ 2
What mistake have on this code ?
text = input() l=list(text) a=-1 b=1 while len(l)>b: a+=b b+=1 k=(l[a]:l.count(l[a]))*len(l) di={k} print(di)
11 Respostas
+ 1
Hi again, Imran Shakil !
How do you mean? Dictionaries are unordered collections. The represention of a dictionary vary with Python version. Later versions of Python (+3.6) makes it possible to affect the representaion. That is what I do with the sorted() function. The dictionaries content is still the same.
You can take away the the sorted function, it just makes the dictionary representation easier to read.
s = input()
d = {c: s.count(c) for c in set(s)}
print(d)
https://code.sololearn.com/c7Q9bLORrURB/?ref=app
+ 6
here is a corrected version of the code
https://code.sololearn.com/c0v3maaOQ8ww/?ref=app
+ 1
Hello Imran Shakil,
It appears that you have accidentally created two similar questions. To avoid confusion, it would be best if you could remove one of these questions. Here is the link to the other question for reference:
https://www.sololearn.com/Discuss/3178684/?ref=app
Thank you :)
+ 1
Per Bratthammar thank you so much...I dont how I should thank you. ...
I hav solved this problem by your help.
0
What is the correct form of this code?
text = input()
l=list(text)
a=-1
b=1
while len(l)>b:
a+=b
b+=1
k=(l[a]:l.count(l[a]))*len(l)
di={k}
print(di)
0
Hi, Imran Shakil !
What are you trying to do? Are you trying to create k as a dictionary, or do you try to slice the list l?
0
k variable is wrong, because:
from while loop, if we type "hello", for instance, the value of a = 9, and value of b = 5 afterwards.
l variable doesn't have the value which has an index of 9 — stated in the "k" variable — therefore error.
**count(I[a])** — also seems to be wrong due to the same reason, as mentioned above.
0
What is the solution of this? :-
Given a string as input, you need to output how many times each letter appears in the string.
You decide to store the data in a dictionary, with the letters as the keys, and the corresponding counts as the values.
Create a program to take a string as input and output a dictionary, which represents the letter count.
Sample Input
hello
Sample Output
{'h': 1, 'e': 1, 'l': 2, 'o': 1}
0
Hi
Per Bratthammar
I want to solve this: -
Given a string as input, you need to output how many times each letter appears in the string.
You decide to store the data in a dictionary, with the letters as the keys, and the corresponding counts as the values.
Create a program to take a string as input and output a dictionary, which represents the letter count.
Sample Input
hello
Sample Output
{'h': 1, 'e': 1, 'l': 2, 'o': 1}
0
# Hi, Imran Shakil !
# You can take a look at this:
s = input() or "Jack and Jill"
d = {c: s.count(c) for c in sorted(set(s))}
print(f"{d = }")
0
Per Bratthammar
Thank you so much. But unfortunetly this code is unable to return expected output.