Playing around with stuff from chapter 1 in "Data Science from Scratch"
"Shannon" in class on Jan 24 2020
from scratch.introduction import users, friendship_pairs
users
friendship_pairs
What is the average number of friends that any given user has?
# Add a 'friends' field to the user list
for user in users:
user['friends'] = []
users
for (user1, user2) in friendship_pairs:
users[user1]['friends'].append(user2)
users[user2]['friends'].append(user1)
users
for user in users:
user['friend_count'] = len(user['friends'])
users
total = 0
for user in users:
total += user['friend_count']
average_friends = total / len(users)
average_friends