def get_bettingest_couples():
# get list of users
users = User.objects.values('id', 'first_name', 'last_name')
# use itertools to get all combinations
global_bettingest_couples = []
for combo in combinations(users, 2):
# for each combo, check how many bets they have with eachother
num_bets = get_couple_bet_number(combo[0]['id'], combo[1]['id'])
# append to list of dictionaries
# e.g. L = [{num_bets: 5, users: ['John Doe', 'Jane Doe']}]
user1_name = combo[0]['first_name'] + ' ' + combo[0]['last_name']
user2_name = combo[1]['first_name'] + ' ' + combo[1]['last_name']
users_names = [user1_name, user2_name]
entry = {'num_bets': num_bets, 'users': users_names}
global_bettingest_couples.append(entry)
# pare down to top 5
pared_global_bettingest_couples = sorted(global_bettingest_couples, key=lambda k: k['num_bets'], reverse=True)[:10]
return pared_global_bettingest_couples
评论列表
文章目录