Is it possible to apply sort within many dictionary?

I try to do 5th Week’s 2nd problem in my way.
with my code I made Individual Dictionaries,bur Can’t apply sort in my code.
is it possible to apply sort with in many dictionaries ??
what should I do?


for i in range (len_read_line):
    if read_line[i] not in temp:
        # print(j,"\t",read_line[i],"\t\t",(read_line.count(read_line[i])))

Could you please elaborate what are you trying to achieve?

Dictionary dic will contain one key:value pair only.
As you are assigning d = dic , you are essentially overwriting the dictionary d, in fact d just points to a new dic each time.
Finally, the dictionary d is containing only one key:value pair.
For meaningful sorting, you need more than one key:value pair.

Hence, would like to know what is the expected outcome of the implementation?

Sir,as you can See the output,my code build separate dictionaries for every word with their value.
After that this is very difficult to find out most frequent word in my text.
That’s why I just want to sort every dictionaries by there value.
So I just want to know is it possible to short many dictionaries by their value?
If yes,then what I need to do???
Thank you sir for paying attention.

As I mentioned earlier,
if there is only one key:value pair in a dictionary it is meaningless to sort that dictionary.
My suggestion here is you should not build individual dictionaries.
Rather, a single dictionary with several key:value pairs.
Use this hint to improve / tweak the logic a bit.

Keep d as your main dictionary, add 'new_word':count to it
And then try sorting it.

1 Like