Open JBPressac opened 7 years ago
What exactly does the "key= lambda userid_numfriends: userid_numfriends[1]" section of the sorted code line do? It generates the correct output (according to the sample output in the text) but I'm lost as to how it computes it? Thanks!
It works perfectly for me!
This is due to the versions of python, the code in book is in version 2. The code mentioned by @JBPressac for version 3 works perfectly.
muito obrigado pela ajuda!
What exactly does the "key= lambda userid_numfriends: userid_numfriends[1]" section of the sorted code line do? It generates the correct output (according to the sample output in the text) but I'm lost as to how it computes it? Thanks!
The sorted function asks how to sort the list! Well we wanna sort the list which each element is a tuple (each element of the list is a tuple of two values). The key parameter wants to know by which value of the tuple the sorted function should work, so with the lambda expression we say that each element of the list is a tuple (x is a tuple so we can sort it with x[0] or x[1]) and sort it with the second value of the tuple.
Hello, The following code is not present at the end of the FINDING KEY CONNECTORS section of https://github.com/joelgrus/data-science-from-scratch/blob/master/code/introduction.py:
For the Python 3 version, I propose the following solution to take the PEP 3113 into account: