human
Python - Choose a dictionary in list which key is closer to a global value
assistant
Here is some code to get a dictionary in list `dicts` which key 'ratio' is closer to a global value 1.77672955975

min(dicts, key=lambda x: (abs(1.77672955975 - x['ratio']), -x['pixels']))

#Warning: this code generation is experimental. Please inspect the code for any bugs before executing.