G
G
germany_is_the_best2020-08-14 20:57:41
Python
germany_is_the_best, 2020-08-14 20:57:41

How to get max value from list?

I surfed almost the entire Internet, and did not find an answer to my question
. How can I still get the maximum height value?

ok = {
    "type": "message_new",
    "object": {
        "message": {
            "date": 1597422901,
            "from_id": ...,
            "id": 88,
            "out": 0,
            "peer_id": ...,
            "text": "",
            "conversation_message_id": 54,
            "fwd_messages": [],
            "important": False,
            "random_id": 0,
            "attachments": [
                {
                    "type": "photo",
                    "photo": {
                        "album_id": -6,
                        "date": 1597402942,
                        "id": ...,
                        "owner_id": ...,
                        "has_tags": False,
                        "post_id": 1036,
                        "sizes": [
                            {
                                "height": 130,
                                "url": ...,
                                "type": "m",
                                "width": 114
                            },
                            {
                                "height": 149,
                                "url": ...,
                                "type": "o",
                                "width": 130
                            },
                            {
                                "height": 229,
                                "url": ...,
                                "type": "p",
                                "width": 200
                            },
                            {
                                "height": 367,
                                "url": ...,
                                "type": "q",
                                "width": 320
                            },
                            {
                                "height": 584,
                                "url": ...,
                                "type": "r",
                                "width": 510
                            },
                            {
                                "height": 75,
                                "url": ...,
                                "type": "s",
                                "width": 66
                            },
                            {
                                "height": 604,
                                "url": ...,
                                "type": "x",
                                "width": 528
                            },
                            {
                                "height": 807,
                                "url": ...,
                                "type": "y",
                                "width": 705
                            },
                            {
                                "height": 1024,
                                "url": "https://sun9-32.userapi.com/gk0ZPzPNa6iqWJ-uqEZrsfyMP8eB_BmcQyGPhg/F3_dI3P_6wA.jpg",
                                "type": "z",
                                "width": 894
                            }
                        ],
                        "text": ""
                    }
                }
            ],
            "is_hidden": False
        },
        "client_info": {
            "button_actions": [
                "text",
                "vkpay",
                "open_app",
                "location",
                "open_link"
            ],
            "keyboard": True,
            "inline_keyboard": True,
            "carousel": False,
            "lang_id": 777
        }
    },
    "group_id": ...,
    "event_id": ...
}

ok = ok['object']['message']['attachments'][0]['photo']['sizes']

I am creating a VK bot in python and would like to get the highest quality image

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
soremix, 2020-08-14
@germany_is_the_best

Loop through all the values ​​and find the largest of them?

max_height = 0
max_url = ''
for size in sizes:
    if size['height'] > max_height:
        max_height = size['height']
        max_url = size['url']

A
Alexander, 2020-08-14
@NeiroNx

So is it like the last one? you can take plast by index -1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question