Answer the question
In order to leave comments, you need to log in
How to get the largest value and the name attached to it from json?
{
"858585885856985": 8.2,
"841224131321321": 100.6
}
Answer the question
In order to leave comments, you need to log in
import operator
# import json
# a = json.loads(...) если json в виде строки прилетает
a = {
"858585885856985": 8.2,
"841224131321321": 100.6
}
print(max(a.items(), key=operator.itemgetter(1)))
# ('841224131321321', 100.6)
json = {
"858585885856985": 8.2,
"841224131321321": 100.6,
"937268282628292": 677.1,
"815158272528286": 87.5
}
num = max(json)
json['name'] = json[num]
del json[num]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question