Skip to content

Instantly share code, notes, and snippets.

@paulmand3l
Last active August 29, 2015 13:56
Show Gist options
  • Save paulmand3l/9243093 to your computer and use it in GitHub Desktop.
Save paulmand3l/9243093 to your computer and use it in GitHub Desktop.
# Create dataset
people = [{'salary': i} for i in range(20000)]
for person in people:
person['friends'] = [(i + person['salary']) % 20000 for i in range(10)]
# people = [..., {'salary': 12308, 'friends': [12308, 12309, 12310, 12311, 12312, 12313, 12314, 12315, 12316, 12317]}, ...]
for person in people:
total_salary = 0
for friend in person.nominated_friends:
total_salary += friend.salary
person.avg_salary_of_friends = total_salary ./ len(person.nominated_friends)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment