suppose the input is like this:
"[{'ability': 18, 'spin': -14, 'strike': 0, 'purity': 5, 'power': 257}, {'ability': -6, 'spin': 147, 'strike': -17, 'purity': 6, 'power': 288}, {'ability': 9, 'spin': 272, 'strike': 10, 'purity': 8, 'power': 256}, {'ability': 0, 'spin': 138, 'strike': -6, 'purity': 19, 'power': 205}]"
I have to sort the input based on the values at the key "ability".
def sort_kvs(lsts):
l = len(lsts)
sort = []
smallest = lsts[0]["ability"]
for i in range (l):
if lsts[i]["ability"] < lsts[0]["ability"]:
smallest = lsts[i]["ability"]
small = lsts[i]
sort.append(small)
return sort
I want the output like this:[{'ability': -6, 'spin': 147, 'strike': -17, 'purity': 6, 'power': 288}, {'ability': 0, 'spin': 138, 'strike': -6, 'purity': 19, 'power': 205}, {'ability': 9, 'spin': 272, 'strike': 10, 'purity': 8, 'power': 256}, {'ability': 18, 'spin': -14, 'strike': 0, 'purity': 5, 'power': 257}]