stats.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:cfbets 作者: joshpelkey 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号