Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5
print(max(users, key=lambda x: x['salary'])['name']) Explanation: You can define HOW a list is sorted or a max found by giving a key. This key has to be a function, that returns for each item what you want to compare, in this case the salary. So the max will be the dictionary jessica. And from that, you access the name.
8th Aug 2019, 2:50 PM
HonFu
HonFu - avatar
+ 6
From my view you should not use individual dicts to store information. you can try this: names = {'mike': 10_000, 'harvey': 15_000, 'jessica': 20_000 } sal_max = 0 for name, salary in names.items(): if salary > sal_max: tmp_name, sal_max = name, salary print(f'Max salary: {tmp_name}: {sal_max}')
8th Aug 2019, 3:17 PM
Lothar
Lothar - avatar
+ 3
Lothar, riffing on your idea: names = {'mike': 10_000, 'harvey': 15_000, 'jessica': 20_000 } print(names[max(names, key=lambda name: names[name])]) Starting to look messy though. 🤣
8th Aug 2019, 3:41 PM
HonFu
HonFu - avatar
+ 1
Aaah, okay! You write a @, and then you should already see the list of people who commented! (If not, start to write the name.)
8th Aug 2019, 3:07 PM
HonFu
HonFu - avatar
0
How do you mean that, what comment text?
8th Aug 2019, 3:00 PM
HonFu
HonFu - avatar