Answer the question
In order to leave comments, you need to log in
How to find largest value in json python?
There is a json document with some information about all Moscow bars.
Initially, json already contains an unreadable data set.
There is such a data set obtained using json.dumps about one bar:
[
...
{
"Address": "Нижний Кисельный переулок, дом 3, строение 1",
"AdmArea": "Центральный административный округ",
"District": "Мещанский район",
"ID": "000069302",
"IsNetObject": "нет",
"Latitude_WGS84": "55.7653669567739740",
"Longitude_WGS84": "37.6215879462381080",
"Name": "Юнион Джек",
"PublicPhone": [
{
"PublicPhone": "(495) 621-19-63",
"global_id": 21025.0,
"global_object_id": 20660594.0,
"system_object_id": "000069302_1"
}
],
"SeatsCount": 30,
"SocialPrivileges": "нет",
"TypeObject": "бар",
"geoData": {
"coordinates": [
37.62158794615201,
55.76536695660836
],
"type": "Point"
},
"global_id": 20660594,
"system_object_id": "000069302"
},
...
]
def get_biggest_bar(data):
biggest_bar = max(data, key=lambda x: x['SeatsCount'])
return biggest_bar, biggest_bar
x['SeatsCount']
Answer the question
In order to leave comments, you need to log in
Here's a slightly more simplified example:
>>> rows = [
{'fname': 'Alex', 'lname': 'Ivanov', 'num': 10},
{'fname': 'Vitaly', 'lname': 'Serov', 'num': 40},
{'fname': 'Sergey', 'lname': 'Popov', 'num': 20},
{'fname': 'Stas', 'lname': 'Borodin', 'num': 30}]
>>> def get_biggest_num(data):
biggest_num = max(data, key=lambda x: x['num'])
return biggest_num
>>> result = get_biggest_num(rows)
>>> result
{'fname': 'Vitaly', 'lname': 'Serov', 'num': 40}
>>> d = dict(name='Petr', num=100)
>>> d
{'name': 'Petr', 'num': 100} # 'name' и 'num' - ключи словаря d, 'Petr' и 100 - их значения соответственно
>>> d['num']
100
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question