以下のデータ構造があります。
[
{
original_price: {
value: ""
},
promos: [ ],
local_id: "122863",
url: "link",
title: "abc",
current_price: {
value: 19.5
},
image: "link",
selections: {
color: "BLACK",
length: "",
size: "7"
},
store: "abc"
},
{
original_price: {
value: ""
},
promos: [ ],
local_id: "122863",
url: "link",
title: "abc",
current_price: {
value: 19.5
},
image: "link",
selections: {
color: "BLACK",
length: "",
size: "9"
},
store: "abc"
},
{
original_price: {
value: ""
},
promos: [ ],
local_id: "122863",
url: "link",
title: "abc",
current_price: {
value: 19.5
},
image: "link",
selections: {
color: "BLACK",
length: "",
size: "6"
},
store: "abc"
}
]
コードで「サイズ」キーでソートしようとしました:
def order_size(self, raw_sizes):
for i in range(len(raw_sizes)):
print i
for j in range(i+1, len(raw_sizes)):
#print raw_sizes
if raw_sizes[j]['selections']['size'] < raw_sizes[i]['selections']['size']:
raw_sizes[j], raw_sizes[i] = raw_sizes[i], raw_sizes[j]
#print raw_sizes
return raw_sizes
しかし、私はできません。私を助けてください。私は結果を期待しています:
[
{
original_price: {
value: ""
},
promos: [ ],
local_id: "122863",
url: "link",
title: "abc",
current_price: {
value: 19.5
},
image: "link",
selections: {
color: "BLACK",
length: "",
size: "6"
},
store: "abc"
},
{
original_price: {
value: ""
},
promos: [ ],
local_id: "122863",
url: "link",
title: "abc",
current_price: {
value: 19.5
},
image: "link",
selections: {
color: "BLACK",
length: "",
size: "7"
},
store: "abc"
},
{
original_price: {
value: ""
},
promos: [ ],
local_id: "122863",
url: "link",
title: "abc",
current_price: {
value: 19.5
},
image: "link",
selections: {
color: "BLACK",
length: "",
size: "9"
},
store: "abc"
}
]
dict内のdictキーでソートされた順番のdictのこのリスト