add_lb_entry = lambda: temp_boards.append([username,userpoints]) temp_boards = [] for username in slots_data: userpoints = slots_data[username]["slots_points"] if len(temp_boards) < 5: add_lb_entry() else: temp_boards.sort(key=lambda points: points[1], reverse = True) if temp_boards[4][1] < userpoints: temp_boards.pop() add_lb_entry() boards_message = "<@%s> -> %s" % (saved_message.author.id,temp_boards) #for username in temp_boards: # boards_message = client.send_message(saved_message.channel, boards_message)