Descargar el Código: patreon.com/pythonmaraton
Join Patreon: patreon.com/pythonmaraton
^Downloadable code & more! Sort dictionary by values:
In this video we will learn how to sort a python dictionary by its values. You can read about how to do this here: https://stackoverflow.com/questions/6...
First let’s open up python and let’s create a string of the alphabet.
Next let’s use that string to create a dictionary. We will create it the values in reverse order, so we can sort
dictionary = {string[::-1][i]:27-(i+1) for i in range(26)}
Now that we have our dictionary let’s sort it by the values.
We import operator. we will create x which will be the sorted by values version of our dictionary.
x = sorted(dictionary.items(), key=operator.itemgetter(1))
So now lets compare. Here is x, which we type dict to convert it back to a normal dictionary, and here is the original dictionary.
You can see x now is numeric.from 1 to 26 sorted by keys.
So there you have it, that is how you can sort a python dictionary by values.
Please subscribe for more python content :D
This is a Python anaconda tutorial for help with coding, programming, or computer science. These are short python videos dedicated to troubleshooting python problems and learning Python syntax. For more videos see Python Help playlist by Rylan Fowers.
✅Subscribe: https://www.youtube.com/channel/UCub4...
📺Channel: https://www.youtube.com/channel/UCub4...
▶️Watch Latest Python Content: https://www.youtube.com/watch?v=myCPg...
▶️Watch Latest Other Content: https://www.youtube.com/watch?v=2YfQs...
🎵Theme Music: https://www.bensound.com/royalty-free...
#PythonMarathon #LearnPython #PythonTutorial
In questa pagina del sito puoi guardare il video online Python Dictionary Sort by Value della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Python Marathon 30 luglio 2019, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 871 volte e gli è piaciuto 6 spettatori. Buona visione!