joelgrus / data-science-from-scratch

code for Data Science From Scratch book
MIT License
8.71k stars 4.52k forks source link

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

Open iphyer opened 9 years ago

iphyer commented 9 years ago

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

iphyer commented 9 years ago

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 commented 9 years ago

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)