(Référence) [Python] Trier les types de collection 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