New course! Every coder should learn Generative AI!
Try a free lesson+ 7
Can anyone shade some light on how this code is working , line no 8 to be more specific .
7 Answers
+ 2
🌀NB🌀 Hopefully this explanation makes sense and helps as well:
https://code.sololearn.com/clkB42bE7Zub/?ref=app
+ 5
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...
+ 5
🌀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. 👌
+ 4
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 .
+ 4
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.
+ 3
Thank you for your insight visph
+ 3
Awesome! I'm really glad you were able to pick up on those details. 👌