data-science-from-scratch
data-science-from-scratch copied to clipboard
Question of the add friends code
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?
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.