def update_leaderboard(self, limit=100):
        session = self.mod_account.session
        subreddit = session.get_subreddit(self.subreddit)

        accounts = sorted(
            [a for a in self.accounts.values() if a.can_comment],
            key=lambda a: a.mean_comment_karma,
            reverse=True,
        )

        leaderboard_md = "\\#|Account|Avg Karma\n--:|:--|--:"
        for rank, account in enumerate(accounts, start=1):
            leaderboard_md += "\n{}|/u/{}|{:.2f}".format(
                rank,
                account.name,
                account.mean_comment_karma,
            )
            if rank >= limit:
                break

        start_delim = "[](/leaderboard-start)"
        end_delim = "[](/leaderboard-end)"
        current_sidebar = subreddit.get_settings()["description"]
        current_sidebar = HTMLParser.HTMLParser().unescape(current_sidebar)
        replace_pattern = re.compile(
            "{}.*?{}".format(re.escape(start_delim), re.escape(end_delim)),
            re.IGNORECASE|re.DOTALL|re.UNICODE,
        )
        new_sidebar = re.sub(
            replace_pattern,
            "{}\n\n{}\n\n{}".format(start_delim, leaderboard_md, end_delim),
            current_sidebar,
        )
        subreddit.update_settings(description=new_sidebar)

        flair_map = [{
            "user": account.name,
            "flair_text": "#{} / {} ({:.2f})".format(
                rank, len(accounts), account.mean_comment_karma),
            } for rank, account in enumerate(accounts, start=1)]
            
        subreddit.set_flair_csv(flair_map)
dataset/ETHPy150Open Deimos/SubredditSimulator/subreddit_simulator/subreddit_simulator.py/Simulator.update_leaderboard/original