def get_leaderboard(): Users_reg = User.objects.all() lst = () for user_reg in Users_reg: uname = user_reg.username score = get_expertise_lvl_rank(uname) uname_str = str(uname) lst = lst + ((uname_str, score),) return sorted(list(lst), key=lambda element: element[1], reverse=True)