joelgrus / data-science-from-scratch

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

Question of the add friends code #7

Open iphyer opened 9 years ago

iphyer commented 9 years ago

Sorry I have a problem concerning the comment in your code:

# and then populate the lists with friendships    
for i, j in friendships:
# this works because users[i] is the user whose id is i
users[i]["friends"].append(users[j]) # add i as a friend of j
users[j]["friends"].append(users[i]) # add j as a friend of i 

to be specific,users[i]["friends"].append(users[j]) # add i as a friend of j add i as a friend of j should be changed into " add j as a friend of i" right?

Because

 >>> list1=['a','b']
 >>> list1.append('c') 
 >>> list1
 ['a', 'b', 'c']

So we can no we add users[j] into users[i]["friends"] right?

wmdataman commented 7 years ago

I thank you for this comment. I just purchased the book and I am having this same problem. I am trying to work it out now.