+ 5
Hy, I'm a begginer, I want to know how to sort a dictionary after values, and to print another dictionary, which is sorted.
How to sort a dictionary in Python
19 ответов
+ 4
You should make that a whole new question.
And write explicitly, what you want to accomplish.
+ 4
by key or by value?
By key:
print(sorted(that_dict.items(), reverse=True))
+ 4
You can, as I said, not output as a dict, but this does come close.
Run and check:
d = {'a': 3, 'b': 2, 'c':4}
print(sorted(d.items(), key=lambda x: x[1], reverse=True))
+ 4
You should post it separately from this thread - as a new question.
+ 3
A dictionary can't be sorted, you can only create a sorted list from a dictionary.
How exactly do you want to sort it?
+ 3
Ha, you found it already. :)
+ 2
Thank you very much. It works! I wrote there print (sorted(dic. items(), key=lambda p:p[1] ,reverse=True)) and was very good!
+ 2
I understand now. I didnt know. Thanks.
+ 2
How about C#
+ 2
Mini
Why have you posted this tinder link.
It is totally inappropriate.
Gotta inform a Mod now!
+ 1
And I have another question.
It is about "deleting"(removing) vowels from a string, without use any additional string, or auxiliary string.
0
Descending
0
For egz: l="I have an apple ."
I want a dictionary which have the letters and how offten they appear there, in string.
For ex: dict={'I':1, 'h' :1,'a':3, etc}
But I have to sort it descending after the values (how offten they appear) and return a dictionary too, with this properties.
0
Like: print(------)
---> {'a':3,'e':2,'i':1 }
Something like this.
0
And I have another question. Actually, I have a lot of questions😂😂😂.
It îs about "deleting"(removing) vowels from a string, without use any additional string, or auxiliar string.
0
I'm writting like this, with some mistakes because I'm romanian. 😂😂
0
In the collections module you can find an object called OrderedDict, which is, as the name says, an ordered dictionary.
Maybe that is what you're looking for. If so, you don't need to do any extra work, because OrderedDict does everything for you.
Hope that's helpful! Good luck!
0
Thanks.
0
Python's strings are immutable objects which makes them faster, so you cannot perform in-place solutions. At least you will need aditional string to remove those vowels.
Immutable = unchangeable