S
S
s4q2021-10-21 19:43:38
Python
s4q, 2021-10-21 19:43:38

How to choose the largest picture from this list of dictionaries?

There is a list of dictionaries:

[{'url': 'https://zepto.scrolller.com/oh-im-die-thank-y7qsj77oc-540x762.jpg',
        'width': 540,
        'height': 762,
        'isOptimized': True},
       {'url': 'https://yocto.scrolller.com/oh-im-diec-765x1080.jpg',
        'width': 765,
        'height': 1080,
        'isOptimized': True},
       {'url': 'https://zepto.scrolller.com/oh-im-die-thsj77oc-1080x1525.jpg',
        'width': 1080,
        'height': 1525,
        'isOptimized': True},
       {'url': 'https://zepto.scrolller.com/oh-im-die-th7l7qsj77oc.jpg',
        'width': 2508,
        'height': 3541,
        'isOptimized': False}]

I need to select the largest picture from it, here it is 2508x3541, how can I do this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2021-10-21
@s4q

item = max(arr, key=lambda n: n['width'] * n['height'])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question