I have a list of dictionaries and trying to sort by key but couldn't get met requirement. I'm new to python. I have tried the following solution
sorted(data, key=itemgetter('key'))
data = [
{
"key" : "NEU",
"value" : 49
},
{
"key" : "POS",
"value" : 30
},
{
"key" : "NEG",
"value" : 39
},
{
"key" : "N/A",
"value" : 10
}
]
I want output like
[ {
"key" : "N/A",
"value" : 10
},
{
"key" : "NEG",
"value" : 39
},
{
"key" : "NEU",
"value" : 49
},
{
"key" : "POS",
"value" : 30
}
]