2016-11-05 62 views
0

第一值我有此词典:的Python - 顺序的字典[键=字符串,值=列表]通过在列表

{u'country__other': [2, u'country', u'other', '-19.6%', '-30.8%', -2326], u'Reg_Device__Desktop': [1, u'Reg_Device', u'Desktop', '-11.3%', '-16.6%', -1112], u'provider_name__facebook': [3, u'provider_name', u'facebook', '-9.2%', '-18.0%', -341]}

密钥是一个字符串(例如, 'u'country__other') 值是列表的长度6

我需要按照FIRST位置(即1,2或3)的升序排列值(列表),并对它们进行for循环。

我该怎么做?

+0

是那个数字保证是唯一的?如果不是这样,物品应该如何分类? – trincot

回答

0

这是我如何做

test = {u'country__other': [2, u'country', u'other', '-19.6%', '-30.8%', -2326], u'Reg_Device__Desktop': [1, u'Reg_Device', u'Desktop', '-11.3%', '-16.6%', -1112], u'provider_name__facebook': [3, u'provider_name', u'facebook', '-9.2%', '-18.0%', -341]} 

for row in test: 
    test[row].sort() 

print test 

结果是: {u'country__other ':[-2326,2, '-19.6%', '-30.8%',u'country', u'other_]',u'Reg_Device__Desktop':[-1112,1,'-11.3%','-16.6%',u'Desktop',u'Reg_Device'],u'provider_name__facebook':[-341,3 ,'-18.0%','-9.2%','u'facebook',u'provider_name']}

希望这是你在找什么。

相关问题