+ 5

Can anyone shade some light on how this code is working , line no 8 to be more specific .

https://code.sololearn.com/ca5a21A10a24/?ref=app

24th Jun 2021, 3:44 PM
⚡NB⚡
⚡NB⚡ - avatar
7 Answers
+ 1
🌀NB🌀 Hopefully this explanation makes sense and helps as well: https://code.sololearn.com/clkB42bE7Zub/?ref=app
25th Jun 2021, 6:22 AM
David Carroll
David Carroll - avatar
+ 4
sort() method take a function as key named argument, wich should get item value as argument and return value(s) used to determine the order... as the lambda function return a tuple with first value is minus the frequency and second is the item value, sort will occur by frequency (from highest to lowest), and in case of same frequency, items from lowest to highest...
24th Jun 2021, 10:52 PM
visph
visph - avatar
+ 4
🌀NB🌀 That's great. My goal was to present a process for developing a mental model for deconstructing and understanding this code. The challenge with getting this right is knowing just how much information to provide and what specifically to focus on. It's also tough to know how to explain some of these things in a way that's easy to follow for any given person. To help me improve on this, which parts of the response did you find most helpful in helping you understand this better? Also, which parts were less helpful? Thanks for the feedback. 👌
25th Jun 2021, 12:20 PM
David Carroll
David Carroll - avatar
+ 2
Thank you David Carroll Sir for all of your hard work on this.It became very easy to grasp the concept now that had me confused for sometime .
25th Jun 2021, 7:25 AM
⚡NB⚡
⚡NB⚡ - avatar
+ 2
David Carroll Sir I enjoyed the analytical intuition that you have provided in the code with the use of multi-line comments especially how the elements get stored along with their respective frequency, how the function is returning tuple, how the negative conversion of f[x] does the trick(this part and the returning tuple part were really helpful), and how elements are getting sorted even if they have the same frequency.
25th Jun 2021, 2:55 PM
⚡NB⚡
⚡NB⚡ - avatar
+ 2
Awesome! I'm really glad you were able to pick up on those details. 👌
25th Jun 2021, 3:31 PM
David Carroll
David Carroll - avatar
+ 1
Thank you for your insight visph
25th Jun 2021, 6:12 AM
⚡NB⚡
⚡NB⚡ - avatar