Hi all, Clould someone please tell how to use the sorted function or equivalent to this function in Python 3 so that I can sort a dictionary. I cannot find any help on this.
Thanks for your time
Hi all, Clould someone please tell how to use the sorted function or equivalent to this function in Python 3 so that I can sort a dictionary. I cannot find any help on this.
Thanks for your time
You could be more specific, maybe this helps?
this_dict = {5:'ada', 3:'pascal', 4:'lisp', 1:'Python', 2:'Icon', 3:'Visual Basic'}
print('The programming languages in key order are:')
print(', '.join(repr(this_dict[key]) for key in sorted(this_dict)))
Thanks TonyJv that works fine ty
It is impossible to sort a dictionary.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.