data-science-from-scratch icon indicating copy to clipboard operation
data-science-from-scratch copied to clipboard

code to sort people from the most friends to the least friends is missing in introduction.py

Open iphyer opened this issue 10 years ago • 2 comments

code to sort people from the most friends to the least friends is missing in introduction.py .

iphyer avatar Jun 15 '15 11:06 iphyer

Oops! I think there must be something you mistake when you write the final draft into the PDF for publishing. The code in PDF book Page 3 shows that id is form 0 to 9. But in code result shown in Page 5 is 1 to 10. I believe you want to user 0 to 9 for code in page 7 clearly shows that. interests list is form 0 to 9.

iphyer avatar Jun 15 '15 11:06 iphyer

I have coded these codes following your book

 num_friends_by_id = [(user["id"],number_of_friends(user)) 
                 for user in users]

 sorted(num_friends_by_id,
   key=lambda (users_id , num_friends): num_friends,
   reverse=True)                   

iphyer avatar Jun 15 '15 13:06 iphyer