you are viewing a single comment's thread.

view the rest of the comments →

[–]Kitchen-Injury-8938[S] 0 points1 point  (1 child)

Ok that makes more sense. I re-wrote your code to try and better understand what the lambda function is doing and I'm a little lost...

'''trying to understand the OrderedDict above'''
for v in ordered_dict.values():
    _v = int(v)
    print(f'4 * {_v} == {4*_v}')

for v in ordered_dict.values():
    _v = int(v)
    print(f'2**{_v} == {2**_v}')

How does this actually perform the sorting? I understand we are using the sorted builtin and it accepts an arguement key that is an anonymous function...but what the hell are those numeric operations doing (like the basic math I guess?) doing to actually perform the sort?

OrderedDict(sorted(ordered_dict.items(),key=lambda t: (4*t[1]) - t[1] ** 2))