[Python] Sorting collection types as a reference

(Reference) [Python] Sort collection types http://qiita.com/ysk24ok/items/b546471c37b2f443f4c7

from operator import itemgetter
b= {'Matsui': 55, 'Ichiroh': 51, 'Kuroda': 18}
print('#-------------------------------------------------------------------')
print('#b=',b,type(b))
c=b.get('Matsui')
print('#c=',c,type(c))
from sympy import *
var('i')
i=-1
for key, value in b.items():
    i=i+1
    print('#b[',i,']=',key,',' ,value)
print('#-------------------------------------------------------------------')
s=sorted(b.items(), key=itemgetter(1))
print('#s=',s,type(s))
print('#s[0]='   ,s[0]   ,type(s[0])   )
print('#s[0][0]=',s[0][0],type(s[0][0]))
print('#s[0][1]=',s[0][1],type(s[0][1]))
print('#-------------------------------------------------------------------')
d=dict(s)
print('#d=',d,type(d))

#-------------------------------------------------------------------
#b= {'Matsui': 55, 'Ichiroh': 51, 'Kuroda': 18} <class 'dict'>
#c= 55 <class 'int'>
#b[ 0 ]= Matsui , 55
#b[ 1 ]= Ichiroh , 51
#b[ 2 ]= Kuroda , 18
#-------------------------------------------------------------------
#s= [('Kuroda', 18), ('Ichiroh', 51), ('Matsui', 55)] <class 'list'>
#s[0]= ('Kuroda', 18) <class 'tuple'>
#s[0][0]= Kuroda <class 'str'>
#s[0][1]= 18 <class 'int'>
#-------------------------------------------------------------------
#d= {'Kuroda': 18, 'Ichiroh': 51, 'Matsui': 55} <class 'dict'>

Recommended Posts

[Python] Sorting collection types as a reference
[Python] Sort collection types
Use pymol as a python library
Use blender as a python module
Launch a Python script as a service
Generate a first class collection in Python
Install Python as a Framework with pyenv
Python as a strongly, dynamically typed language
[python] Create a list of various character types
python memo: Treat lists as a set type
About python reference
Python reference page
I made a Twitter BOT with GAE (python) (with a reference)
(Python) Treat integer values as a set of flags
Specify a subcommand as a command line argument in Python
A collection of code often used in personal Python
A collection of Excel operations often used in Python
python (3) dominer ORM collection
[Python] Take a screenshot
Create a Python module
A python lambda expression ...
python small story collection
Daemonize a Python process
Create a Python environment
[Python] Sorting Numpy data
Python3> round (a --b, 7)
Organize types in Python
Displaying DICOM images in rudimentary Python as a medical professional
A collection of competitive pro techniques to solve with Python
Grayscale image is displayed as a color image in OpenCV / Python
Creating a GUI as easily as possible with python [tkinter edition]
[Python] A program that finds the most common bird types
[Python] Use JSON format data as a dictionary type object